0

I have a div contained within an anchor like so:

<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. I know you can do it simply for the div like so:

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

But I want it to change when you hover over the text also

Lee
  • 1,485
  • 2
  • 24
  • 44
  • 1
    You need to understand that div is a block element and anchor is an inline element. What you doing is unnatural and unnecessary... Put a span in the anchor or just style it but itself – felix91 Nov 07 '16 at 10:05
  • 1
    http://stackoverflow.com/questions/1827965/is-putting-a-div-inside-an-anchor-ever-correct – Jose Rui Santos Nov 07 '16 at 10:07
  • Thanks both, I've changed it to a – Lee Nov 07 '16 at 10:12

4 Answers4

1

Is this the sort of thing you're after?

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

https://jsfiddle.net/d7tc0sq8/

Andy Holmes
  • 7,817
  • 10
  • 50
  • 83
1
<a class="chk" href="href">
  <div class="chk-div">Text Here</div> 
</a>


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

Hope this will help.

Mohamed dev
  • 172
  • 1
  • 8
0
<a class="ckk" href="#">
Text Here
</a>

.chk {padding:10px; border:1px solid black;}
.chk:hover{border-color:green;}
felix91
  • 452
  • 3
  • 11
0

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

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

css:

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

}
G.L.P
  • 7,119
  • 5
  • 25
  • 41