user1485019
user1485019

Reputation: 11

Why when I change the link color in one div element, it changes it in another?

Here is some of my CSS code. When I change the color in the #container2 element, it changes the color for the link in the #container1 element as well. Why is this?

#container1 {
display:block;
position:relative;
margin: 0 auto 0 auto;
width:auto;
background-color: #f26822;
}
#container1 #mainnavigation {
height:20px;
width:960px;
background-color: #f26822;
margin: 0 auto 0 auto;
}

#container1 #mainnavigation ul {
    list-style-type: none;
    margin: 0;
    overflow: hidden;
    padding: 0;
}
#container1 #mainnavigation li {
    background-color: #f26822;
    float: left;
    height: 20px;
    width: 137px;
}

#container1 #mainnavigation a:link,a:visited {
    color: #FFFFFF;
    display: block;
    font-weight: bold;
    padding: 0%;
    text-align: center;
    text-decoration: none;
    text-transform: uppercase;
    width: 100%;
    border-radius:10px;
}

#container1 #mainnavigation a:hover,a:active {
    color: #27348B;
    background-color:#FF8000;
}

Thats code for my first set of links, below is code for a second link in another element

#container2 #content a:link,a:visited {
font-family:calibri;
font-size:16px;
color: ;
text-decoration:none;
}

#container2 #content a:hover,a:active {
color: #000;
}

Ok I just entered all the code into jsFiddle and it works fine, but when I test it using my browser it doesn't? Help?

Upvotes: 1

Views: 278

Answers (1)

Vin Burgh
Vin Burgh

Reputation: 1419

If you take a second look at your CSS, you'll notice that you are declaring your styles for a:visited links at the global level. Instead, just as you declared styles for a:link and a:hover by their respective parents, you will need to do so for a:visited as well. Your stylesheet should reflect the following:

...

#container1 #mainnavigation a:link, #container1 #mainnavigation a:visited {
 color: #FFFFFF;
 display: block;
 font-weight: bold;
 padding: 0%;
 text-align: center;
 text-decoration: none;
 text-transform: uppercase;
 width: 100%;
 border-radius:10px;
}

#container1 #mainnavigation a:hover, #container1 #mainnavigation a:active {
 color: #27348B;
 background-color:#FF8000;
}

#container2 #content a:link, #container2 #content a:visited {
 font-family:calibri;
 font-size:16px;
 color: #000;
 text-decoration:none;
}

#container2 #content a:hover, #container2 #content a:active {
 color: #000;
}

Upvotes: 1

Related Questions