简体   繁体   English

CSS-在anchor:hover中更改div的边框颜色

[英]CSS - Change border-color of div within anchor:hover

I have a div contained within an anchor like so: 我的锚中包含一个div,如下所示:

<a class="chk" href="href">
  <div class="chk-div"></div> Text Here
</a>

I want it so that when you hover over the <a> , the border-color of the child <div> changes. 我想要它,当您将鼠标悬停在<a> ,子<div>的边框颜色会更改。 I know you can do it simply for the div like so: 我知道您可以像这样简单地为div做到这一点:

.chk-div:hover {
  border-color: green;
}

But I want it to change when you hover over the text also 但是当您将鼠标悬停在文本上时,我希望它会更改

Is this the sort of thing you're after? 这是您所追求的吗?

.chk:hover .chk-div {border: solid 1px green;}

https://jsfiddle.net/d7tc0sq8/ https://jsfiddle.net/d7tc0sq8/

<a class="chk" href="href">
  <div class="chk-div">Text Here</div> 
</a>


.chk-div:hover {
  border: 1px solid green;
}

Hope this will help. 希望这会有所帮助。

<a class="ckk" href="#">
Text Here
</a>

.chk {padding:10px; border:1px solid black;}
.chk:hover{border-color:green;}

Try like this: Demo 尝试这样: 演示

As you are giving border for div, its a block level element, so use it as inline-block or use span like this 当您为div提供边框时,它是一个块级元素,因此可以将其用作内嵌块或使用跨度,例如

<a class="chk" href="href">
  <span class="chk-div">Text</span>  Here
</a>

css: CSS:

.chk-div:hover {
  border: 1px solid green;

}

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

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