Reputation: 9047
I have this following HTML elements.
<div id="theparent">
<div class="thechild">
<div class="anotherchild"></div>
</div>
</div>
and the CSS for those elements.
#theparent{width: 90%;}
.thechild{width: 100%; padding: 10px;}
.anotherchild{}
Now what I want is that the .anotherchild
div width must be equal or leveled to the width of the .theparent
div while keeping the padding of .thechild
div, how to do that? any suggestions, recommendations and ideas is greatly appreciated.
Upvotes: 0
Views: 1458
Reputation: 86
Since .thechild's padding is known, you can use the CSS3 calc() function to add that known value to what ever value 100% may be and fix the offset with a negative margin.
.anotherchild{
margin-left:-10px;
width:calc(100% + 20px);
}
Upvotes: 1
Reputation: 208022
Add a box-sizing
rule to the child div:
.thechild {
width: 100%;
padding: 10px;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
jsFiddle example (border added for visibility)
Upvotes: 1