简单的样式
要实现您要查找的内容,您可以将一个类应用于将容纳您的侧边栏链接的容器(我们将在此示例中使用 .sidebar),然后定位属于该容器内的任何锚点.sidebar 类应用于。
标记:
<div class="sidebar">
<a href="/">Lorem Ipsum</a>
<a href="/about">Lorem Ipsum</a>
<a href="/contact">Lorem Ipsum</a>
</div>
CSS:
/* font family, text-decoration, and font-size for all of the links you want to style */
.sidebar a {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
text-decoration: none;
font-size: 1em;
}
/* color for the unvisited links you want to style */
.sidebar a:link {
color: #FF0000;
}
/* color for the visited links you want to style */
.sidebar a:visited {
color: #00FF00;
}
/* underline the links you want to style when hovered */
.sidebar a:hover {
text-decoration: underline;
}
/* color for the active links you want to style */
.sidebar a:active {
color: #0000FF;
}
提示:如果您使用描述性(“语义”)类名,如 .sidebar,您(和其他开发人员)可以更轻松地识别正在设置样式的元素。
进一步定制:
如果您想对一个(或多个)侧边栏链接进行一些额外的自定义以使其从其他链接中脱颖而出,该怎么办?好吧,让我们假设您希望其中一个链接是绿色的。
您可以通过将一个类应用于我们容器中的一个锚点来实现这一点。
标记:
<div class="sidebar">
<a href="index.html" class="green">Lorem Ipsum in GREEN!</a>
<a href="/about">Lorem Ipsum</a>
<a href="/contact">Lorem Ipsum</a>
</div>
CSS:
/* font family, text-decoration, and font-size for all of the links you want to style */
.sidebar a {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
text-decoration: none;
font-size: 1em;
}
/* color for the unvisited links you want to style */
.sidebar a:link {
color: #FF0000;
}
/* color for the visited links you want to style */
.sidebar a:visited {
color: #00FF00;
}
/* underline the links you want to style when hovered */
.sidebar a:hover {
text-decoration: underline;
}
/* color for the active links you want to style */
.sidebar a:active {
color: #0000FF;
}
/* override the color of one of our sidebar links to be green! */
.sidebar a.green {
color: green;
}
我希望这会有所帮助!
编辑:为简单起见进行了清理。