I have a parent with red border. When the user hovers on children, I am trying to change the children's border to overlap the parent. How can I achieve this?
.parent{
border:1px solid red;
display:inline-block;
}
.parent a {
display:block;
padding:1em;
border-bottom:1px solid #ddd;
}
.parent a:hover{
border:1px solid #ddd;
}
<div class="parent">
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
</div>
I made some changes on your style:
.parent{
display:inline-block;
}
.parent a {
display:block;
padding:1em;
border-right:1px solid red;
border-left:1px solid red;
border-bottom:1px solid #ddd;
border-top: none;
}
.parent a:first-of-type{
border-top:1px solid red;
}
.parent a:last-of-type{
border-bottom:1px solid red;
}
.parent a:hover{
border-color:#ddd;
}
see the result here https://jsfiddle.net/IA7medd/343ydvhs/
So long as you know the width of the borders and are able to use relative positioning... I have exaggerated the borders here for clarity.
.parent {
border:5px solid red;
display:inline-block;
position: relative;
}
.parent a {
display:block;
padding:1em;
border-bottom:1px solid #ddd;
position: relative;
}
.parent a:hover{
border:5px solid #ddd;
margin: -5px;
}
https://jsfiddle.net/kd0gf31z/
You could achieve this through the use of absolutely positioned pseudo elements, like so:
*,*::before,*::after{box-sizing:border-box;font-family:sans-serif;}
.parent{
border:1px solid red;
display:inline-block;
}
.parent a{
display:block;
padding:1em;
border-bottom:1px solid #ddd;
position:relative;
}
.parent a:last-child{
border:0;
}
.parent a:hover::after{
border:1px solid #ddd;
bottom:-1px;
content:"";
left:-1px;
position:absolute;
right:-1px;
top:-1px;
}
<div class="parent">
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With