Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="http://pmob.co.uk/pob/centred-float.htm" rel="noreferrer">http://pmob.co.uk/pob/centred-float.htm</a>:</p> <blockquote> <p>The premise is simple and basically just involves a widthless float wrapper that is floated to the left and then shifted off screen to the left width position:relative; left:-50%. Next the nested inner element is reversed and a relative position of +50% is applied. This has the effect of placing the element dead in the center. Relative positioning maintains the flow and allows other content to flow underneath.</p> </blockquote> <h2>Code</h2> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#buttons{ float:right; position:relative; left:-50%; text-align:left; } #buttons ul{ list-style:none; position:relative; left:50%; } #buttons li{float:left;position:relative;}/* ie needs position:relative here*/ #buttons a{ text-decoration:none; margin:10px; background:red; float:left; border:2px outset blue; color:#fff; padding:2px 5px; text-align:center; white-space:nowrap; } #buttons a:hover{ border:2px inset blue;color:red;background:#f2f2f2;} #content{overflow:hidden}/* hide horizontal scrollbar*/</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="buttons"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Button 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Button 2's a bit longer&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Butt 3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Button 4&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
 

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