Note that there are some explanatory texts on larger screens.

plurals
  1. POcenter and position elements in CSS
    primarykey
    data
    text
    <p>I'm stuck with my HTML/CSS code where I need to <strong>horizontally center</strong> two divs (A, B) with background images in one absolutely positioned div (C). </p> <p>Bering in mind that:</p> <ul> <li>bottom edge of larger div (A) needs to be at the bottom of (C). </li> <li>top edge of (A) needs to be at the top edge of (B).</li> <li>(B) needs to be behind (A) - which needs the same <code>position</code> property, I think.</li> <li>number of added inner div elements to the (C) div is not restricted</li> </ul> <p>Here is my fiddle where I managed to position the (A) div inside the (C) <a href="http://jsfiddle.net/meridius/DGexR/" rel="nofollow noreferrer">http://jsfiddle.net/meridius/DGexR/</a> But no matter what I do, I can't accomplish the rest.</p> <p><strong>EDIT:</strong><br> Here is how it should look like <img src="https://i.imgur.com/duKBXVS.png" alt="enter image description here"></p> <p><strong>Code preview:</strong><br> <em>For working example (with background images) please see above mentioned fiddle.</em></p> <p>HTML</p> <pre><code>&lt;div class="desk"&gt; &lt;div class="figure"&gt; &lt;div class="type sprites-sachy sprite-WKing"&gt;&lt;/div&gt; &lt;div class="special sprites-sachy sprite-halo"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>.desk { /* this class must not be touched */ position: absolute; top: 129px; left: 202px; border: 1px solid #FF0000; width: 65px; height: 65px; padding: 0; float: left; } .figure { bottom: 0; left: 50%; position: absolute; } .type { margin-left:-50%; z-index:2; } .special { border: 1px solid #008000; z-index:1; /* display:none; uncomment this to see .figurka centered how it is supposed to */ } </code></pre> <hr> <p><strong><em>NOTE:</em></strong><br> <em>I'd like to avoid this question being closed as too localized, so let me state first that I believe that I'm not the only one having problems positioning (and centering) elements in CSS.</em></p>
    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. 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