Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

margin left and right on width 100%

Tags:

html

css

I have a div that's set to width 100%. I wanted to set a margin right and left of 20px. For some reason only the left is being pushed over 20px. It ignores the right. Is this because of the 100%?

like image 404
Chapsterj Avatar asked Jul 17 '26 04:07

Chapsterj


1 Answers

Remove the width. As with all block elements, divs will automatically expand to fill the available width. When you specify a width of 100%, you are telling it to be the same size as its container, not to fill the available width. As width does not include margins, specifying the margin in addition to the width causes the div to be shifted to the right by the left margin amount, and the right margin exists off the screen.

like image 148
gilly3 Avatar answered Jul 18 '26 17:07

gilly3



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!