简体   繁体   中英

Hover to a div, change the color of the <a> element inside this div

What I want to do is quite easy, my code is as below:

html:

<div class="outer">
    <a href="">line 1</a>
    <a>line 2</a>
</div>

css:

a{
    display:block;
    text-decoration:none;
}

.outer:hover{
    color:#ff0000;
}

The problem is, when I add href="" to the , the hover can't work. If I remove the href="" , when I move my mouse pointer to the div, the hover effect works.
Souce is here

Anybody know what's the reason? Thanks!

You just need to change the color of the <a> element when the <div> is hovered over:

.outer:hover a{
    color:#ff0000;
}

Fiddle: Fiddle

You can use this.

.outer:hover a{
    color:#ff0000;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM