今天要为大家介绍一下在CSS中如何用图片做导航。首先,在HTML中定义导航的链接,在每个链接中添加一个图片标签,例如: 接下来,我们使用CSS来控制导航链接的样式,我们要设置链接为块级元素(dis...
今天要为大家介绍一下在CSS中如何用图片做导航。
首先,在HTML中定义导航的链接,在每个链接中添加一个图片标签,例如:
<a href="home.html"><img src="home.png"></a>
<a href="about.html"><img src="about.png"></a>
<a href="contact.html"><img src="contact.png"></a>
nav a {
display: block;
width: 50px;
height: 50px;
}
nav a[href="home.html"] {
background-image: url("home.png");
}
nav a[href="about.html"] {
background-image: url("about.png");
}
nav a[href="contact.html"] {
background-image: url("contact.png");
}
nav a:hover {
opacity: 0.8;
}
nav a.active {
opacity: 1;
}
nav a {
display: block;
width: 50px;
height: 50px;
}
nav a[href="home.html"] {
background-image: url("home.png");
}
nav a[href="about.html"] {
background-image: url("about.png");
}
nav a[href="contact.html"] {
background-image: url("contact.png");
}
nav a:hover {
opacity: 0.8;
}
nav a.active {
opacity: 1;
}