0
I need to put a div with the property position = absolute. However, the div father has a padding and the width: 100% of div son does not respect this padding.
Would the only way out be to define the width with the javascript?
I put an example here:
.master {
background-color: red;
width: 200px;
height: 300px;
padding: 10px;
position: relative;
}
.child {
width: 100%;
height: 30px;
background-color: yellow;
position: absolute;
}
<div class="master">
<div class="child">
</div>
</div>

I don’t understand if you want to respect the padding and reduce the width of the yellow, or if you just support the yellow. Absolute positioning does not respect ancestral padding.
– bfavaretto
I want to respect the padding
– Roberto de Campos
The
paddingchanges the size of the element, so it is expected that the child element, configured withwidth: 100%, also get 220px wide. Take out theposition: absolute, as @bfavaretto said and will have an element with 200px.– Woss
If you want a div to occupy the entire width of the father, respecting the paddings, why then use
position: absolute? Using div in your pattern already does this. Just take the propertieswidthandpositionfrom there.– Dudaskank
Ali was just an example, I need
position: absolutebecause thatdivyellow will float over the remaining content– Roberto de Campos