问题
Hi there i had a nav bar which was working perfectly. Then i added a lightbox effect. Both work perfectly however in my css they are messing up. When i added some css to lightbox effects to the div it messes up my navigation bar. I think its something to do with the a
tag. My code is below
Html:
<div id="nav">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">Regsiter</a></li>
<li><a href="#contact">Rules</a></li>
<li><a href="#about">Photo's</a></li>
<li><a href="#about">Contact Us</a></li>
</ul>
</div>
<div class = "lightbox">
<a href="images/image1.jpg" rel="lightbox[group]"><img src="images/image1t.jpg" /></a>
<a href="images/image2.jpg" rel="lightbox[group]"><img src="images/image2t.jpg" /></a>
<a href="images/image3.jpg" rel="lightbox[group]"><img src="images/image3t.jpg" /></a>
<a href="images/image4.jpg" rel="lightbox[group]"><img src="images/image4t.jpg" /></a>
<a href="images/image5.jpg" rel="lightbox[group]"><img src="images/image5t.jpg" /></a>
<a href="images/image6.jpg" rel="lightbox[group]"><img src="images/image6t.jpg" /></a>
</div>
CSS:
#nav ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
#nav ul li
{
float:left;
}
#nav a:link,a:visited
{
display:block;
width:163.2px;
height: 35px;
font-weight:bold;
color:#FFFFFF;
background-color:#181818;
text-align:center;
text-decoration:none;
text-transform:uppercase;
line-height: 35px;
}
#nav ul li a:hover
{
background-color:#989898;
}
//Below is the lightbox CSS
a
{
border:3px solid #ccc;
display:block;
float:left;
margin:10px;
}
a img
{
margin:3px;
}
a:hover
{
border:3px solid #666;
}
img
{
display:block;
}
Like i said. If i delete the light box CSS the nav bar works fine. When i add it, the border on the nav bar and everything changes. I think it something to do with them both having the a
tag but not sure. Thanks for the help.
回答1:
Apply the lightbox CSS only to elements inside the lightbox:
.lightbox a{
border:3px solid #ccc;
display:block;
float:left;
margin:10px;
}
.lightbox a img{
margin:3px;
}
.lightbox a:hover{
border:3px solid #666;
}
.lightbox img{
display:block;
}
Demo: http://jsfiddle.net/42BjW/ (I don't have the lightbox JS, so obviously the lightbox itself is not working)
回答2:
just add .lightbox
in front of your later classes , the lightbox css
来源:https://stackoverflow.com/questions/15800054/navigation-bar-messing-with-other-elments-in-css