【发布时间】:2017-08-15 06:22:10
【问题描述】:
我在设置嵌套 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>
【问题讨论】:
-
!important不工作吗? -
@Siraj,是的,它正在工作,谢谢!
-
这是否意味着我的答案应该被标记为接受的答案?
标签: html css class hyperlink colors