Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fluid box with absolute position while parent has a box-sizing of border-box?

I have two divs 'parent' and 'child'. Both boxes has a box-sizing property with value of border-box. Parent has fixed width and padding while I need child fluid width and absolute position. Child should be inside the parent div but instead its behaving kind a weird and took parents full width including padding which pushes it outside the parent. My markup looks like:

<div class="parent">
   <div class="child"></div>
</div>

and CSS:

.parent{
    width: 500px;
    height: 500px;
    padding: 45px;
    box-sizing: border-box;
    background-color: red;
    position: relative;
}

.child{
    width: 100%;
    height: 200px;
    position: absolute;
    bottom: 10px;
    box-sizing: border-box;
    background-color: orange;
}

You can also see it at JSFiddle. Please suggest!

like image 700
Imran Avatar asked Jan 25 '26 02:01

Imran


1 Answers

You need to add a left: 0 to your child element to keep it aligned with the parent element. Check here.

like image 79
Jsalinas Avatar answered Jan 28 '26 05:01

Jsalinas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!