2014-06-23 107 views
0

I'm fairly new to HTML/CSS so excuse me if this is a simple question but my a:hover (using an id and not a class) isn't working inside an a href tag but when I use it in a th tag it does.懸停不起作用<a href> tag

HTML

<a href='http://www.example.com' id='link1'>Example Text</a> 

CSS

#link1 a:hover { 
text-decoration: none; 
color: #E0E0E0; 
} 

The thing is that if I put it in a div and set it as a class instead of an id, it works but then moves the rest of the links afterward down a line on the page.

+0

我想這可能是因爲你正在尋找一個「A」鏈接裏面的#鏈接1。試試#link1:懸停也許。 – ncdreamy

回答

3

這是因爲您試圖在id'link1'內找到錨鏈接,而link1是錨鏈接。試試這個:

a#link1:hover { 
    text-decoration: none; 
    color: #E0E0E0; 
} 

http://jsfiddle.net/kF8ey/

+1

謝謝!我真的很感激<3 –

2

Your selector is incorrect. Try this:

#link1:hover { 
    text-decoration: none; 
    color: #E0E0E0; 
} 

By using: #link1 a:hover, your telling your code too look for a link named #link1 and then look for an anchor tag inside of it. Clearly you just want #link1 itself.

Soultion in a fiddle: http://jsfiddle.net/9GXg8/