Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For <code>margin-left:auto;</code> and <code>margin-right:auto;</code> to work, the element needs to have a width. So try something like:</p> <pre><code>margin-left: auto; margin-right: auto; width: 600px; </code></pre> <p><strong>UPDATE:</strong></p> <p>Since you seem to alter your examples all the time, here is a very basic understanding of how <code>display</code> and <code>margins</code> work:</p> <p>To have any box centered within another box, you need to do two things:</p> <p>a) Give the outer box a width (otherwise the inner box doesn't know what to center against</p> <p>b) The inner box needs to have <code>margin: 0 auto</code> (this is the same as <code>margin-left: auto; margin-right: auto;</code>)</p> <p>Also, both boxes need to be block level elements (i.e. have <code>display: block</code>, NOT <code>display: inline;</code>)</p> <p>So put together it will look like this:</p> <p>HTML:</p> <pre><code>&lt;section id="outer"&gt; &lt;section id="inner"&gt;&lt;/section&gt; &lt;/section&gt; </code></pre> <p>CSS:</p> <pre><code>#outer { width: 600px; display: block; border: 1px solid red; } #inner { margin-left: auto; margin-right: auto; width: 200px; height: 200px; border: 1px solid green; } </code></pre> <p>This will give you a green box of 200px by 200px centered within a red box of width 600px.</p> <p>Now, if you want two elements side by side within the green box, you can add your inline elements there, i.e.</p> <pre><code>&lt;section id="outer"&gt; &lt;section id="inner"&gt; &lt;article&gt;Hi&lt;/article&gt; &lt;article&gt;Hi agian!&lt;/article&gt; &lt;/section&gt; &lt;/section&gt; #outer { width: 600px; display: block; border: 1px solid red; } #inner { margin-left: auto; margin-right: auto; width: 200px; height: 200px; border: 1px solid green; } #inner article { display: inline; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload