ネストされたdivのリンクの色を設定する際に問題があります。リンクは、親div要素のリンクのデフォルトのスタイルで表示されます。一言で言えばネストされたdiv内のリンクのスタイルをオーバーライド
、我々はHTMLコードを次しているとしましょう:
<body>
<div id="message">
<div class="wrap">
<a href="...">Link 1</a>
<a href="...">Link 2</a>
<div class="website">
<div class="website-button">
<a href="...">Link 3</a>
<a href="...">Link 4</a>
</div>
</div>
</div>
</div>
</body>
私が使用#message/wrap
コンテナ内Link 1
とLink 2
要素のスタイルに:
#message a:link { color: rgba(85, 165, 255, 1.0); }
#message a:visited { color: rgba(85, 165, 255, 1.0); }
#message a:hover { color: rgba(95, 185, 255, 1.0); }
#message a:active { color: rgba(95, 185, 255, 1.0); }
をまた、私はLink 3
を必要としますLink 4
のリンクは白色になります。私はこれらのリンクをこのようにスタイリングしています:
.website-button a:link,
.website-button a:visited,
.website-button a:hover,
.website-button a:active {
color: #ffffff;
}
問題は、私は.website-button
要素内のリンクのスタイルを上書きすることはできませんです。彼らは私が何をしても青いままです。以下は
私のページからの抜粋です:
<html>
<head>
<style>
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap {
max-width: 800px;
margin: 32px auto;
padding: 0 24px;
}
#message {
overflow: hidden;
background: rgba(62, 72, 119, 1.0);
color: rgba(255, 255, 255, 1.0);
}
#message a:link { color: rgba(85, 165, 255, 1.0); }
#message a:visited { color: rgba(85, 165, 255, 1.0); }
#message a:hover { color: rgba(95, 185, 255, 1.0); }
#message a:active { color: rgba(95, 185, 255, 1.0); }
.website {
width: 100%; height: auto;
margin: 0.6rem 0 1.6rem 0;
}
.website-button {
width: 50%;
height: auto;
margin: 0 auto;
padding: 12px 18px;
background: #f50;
font-size: 1.8rem;
line-height: 2.0rem;
text-transform: none;
text-align: center;
font-weight: 700;
}
.website-button a:link,
.website-button a:visited,
.website-button a:hover,
.website-button a:active {
color: #ffffff;
}
</style>
</head>
<body>
<div id="message">
<div class="wrap">
<h3>Hello!</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<h3>Twitter: <a href="https://twitter.com/zimnovich">ZimNovich</a></h3>
<div class="website">
<div class="website-button"><a href="https://soundcloud.com/zimnovich/mobirrel-radio-edit">Listen it on SoundCloud</a></div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<h3>Instagram: <a href="https://instagram.com/zimnovich">ZimNovich</a></h3>
</div>
</div>
</body>
</html>
http://codepen.io/anon/pen/evrgay
は '!important'は機能しませんか? – Siraj
@Siraj、はい、それは働いています、ありがとう! – ezpresso
それは私の答えが受け入れられた答えとしてマークされるべきであるということですか? – Siraj