Reputation: 51
There is an outer div, and an inner div element. Sometimes I see that the inner div is wider than the outer div.
When does this happen? And how to overcome this issue?
<div id="outer">
<div id="inner"></div>
</div>
Upvotes: 0
Views: 5719
Reputation: 103780
According to comment the reason the inner element is wider than parent is caused by the margin/padding. This happens when you set
(width + padding + margin + border) of child > parent width
Workarounds :
(width + margin) of child =< parent width
demoUpvotes: 6
Reputation: 74
<div id="outer">
<div id="inner">Inner Text</div>
</div>
<style type="text/css">
#inner, #outer {
box-sizing: border-box;
width: 100%;
border: solid 1px #000;
padding: 1%;
}
</style>
Upvotes: -1