I have a container on my test site:
#container { margin: 0 auto; }
Then I added the left vertical menu and on some small screens that menu is not fully visible.
Like my old laptop :-)
I want to keep the margin:auto
setting in place but I want to move the whole #container
a little bit to the right.
I have tried #container {margin-left:10px;}
, but to no avail.
Can we align an element by setting margin-left and margin-right? A Yes it's possible.
The auto Value You can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.
Left is the position of your entire element, margin-left is the amount of your left margin.
margin-left: auto; The auto keyword will give the left side a share of the remaining space. When combined with margin-right: auto , it will center the element, if a fixed width is defined.
Playing with firebug, it's good to use:
#container { margin: 0 auto; position:relative; left:10px; }
Hope it solves...
The simplest approach would be to introduce another element (or style another element if it's already available). Thus, you might have:
<div style="margin-left: 10px;"> <div id="container" style="margin: auto;">...</div> </div>
That way the centering is being done within a container div that's already got the appropriate left-hand padding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With