tags:

views:

179

answers:

3

I have #container {margin: 0 auto;} on my test site Than 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 little bit right. Could it be done some how? #container {margin-left:10px;} doesn't work ...

+1  A: 

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.

VoteyDisciple
not sure how easily I can introduce new element in WordPress ....
Radek
it should be `20px` to shift it 10px to the right.
nickf
+3  A: 

Playing with firebug, it's good to use:

#container {
 margin: 0 auto;
 position:relative;
 left:10px;
}

Hope it solves...

Zuul
@Zuul: WORKS!!!! Thank you so much. I am still learning how to use firebug and believe me that I was playing with it already. It is more about my css experience I would say....
Radek
+1 for a solution without any extra markup
nickf
not only any extra markup but it is also so elegant (at least for me :-)
Radek
It's all about the "love" for the code :) Tks nickf and Radek, clad I could help!
Zuul
Gorgeous solution — clean and very clear. This is why I love CSS.
Dan M
A: 

If you wrap your #container div in another div with double the left margin, that will work.

  #wrap {
    margin-left: 20px;
  }
  .centre { /* this would be your #container */
    width: 100px;
    height: 40px;
    margin: auto;
    background-color: #f00;
  }
  #wrap .centre {
    background-color: #00f;
  }

The HTML:

  <div class="centre"></div>
  <div id="wrap">
    <div class="centre"></div>
  </div>

http://jsbin.com/emogu3

nickf