Is there a way to adjust the width and alignment of the .inner
class to perfectly match its parent?
Potential solutions include:
- Applying
box-sizing: content-box
and adjusting theleft
property by the border size. - Adjusting both the
left
andright
properties by -1px each.
However, these solutions may not be ideal as they require knowledge of the parent's border size or the use of box-sizing: content-box
, which we want to avoid.
Additionally, changing the DOM hierarchy is not an option since we need to style elements generated by a JS-framework.
Do you have any better alternatives?
*, *:before, *:after{
box-sizing: border-box;
}
.outer{
border: 1px solid black;
width: 50%;
position: relative;
}
.inner{
position: absolute;
top: 100%;
left: 0px;
width: 100%;
border: 1px solid black;
// box-sizing: content-box;
// left: -1px;
}
<div class="outer">
text
<div class="inner">Inner</div>
</div>