简体   繁体   English

将鼠标悬停在div上时显示文本装饰

[英]Show text-decoration when hover over div

I was wondering how I could make a link turn blue when they hover over the whole div and not just the link itself. 我想知道当鼠标悬停在整个div上而不仅仅是链接本身时,如何使链接变为蓝色。 Would this be possible to do with just HTML & CSS? 仅使用HTML和CSS就能做到吗?

For an example: If I had ( jsfidde ), how would I make the link turn blue if you just hovered over the gray and not the actual link? 例如:如果我有( jsfidde ),如果您只是将鼠标悬停在灰色而不是实际链接上,那么如何使链接变成蓝色?

<style>
    #parent {
        background-color: gray;
        height: 100px;
        width: 200px;
    }
    #parent img {
        margin: auto;
        line-height: 90px;
    }
    #caption a {
        text-decoration: none;
        color: black;
    }
    #caption a:hover {
        color: blue;
    }
</style>
<div id="parent">
    <img src="http://www.cedexis.com/images/icons/32-social.png?1389641973" />
    <div id="caption"> <a href="jsfiddle.net">This is a caption</a>

    </div>
</div>
#parent:hover a
{
    color: blue;
}

DEMO 演示

#parent:hover #caption a {
    color:blue;
}

Like this: http://jsfiddle.net/techsin/7MLSb/2/ 像这样: http : //jsfiddle.net/techsin/7MLSb/2/

#parent:hover a {
    color: blue;
}

when parent is hovered turn all a's in them blue. 当父母悬停时,将其中的所有a变成蓝色。

Use this 用这个

#parent:hover #caption a {
    color: blue;
}

Instead of this 代替这个

#caption a:hover {
    color: blue;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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