Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to completely shrink wrap and center an element
    primarykey
    data
    text
    <p>I am using the following code to create a shrink wrapped and centered page. Everything is fine if the browser window is wider than the maximum potential width. In this case, there are three floated paragraphs with fixed widths. If the window is wide enough so that they can all float on the same line, the div is centered and wrapped correctly. But when the browser is narrower, and one of the paragraphs wraps to the next line, the div expands to the full width of the window and is no longer shrink wrapped. I have tried everything I can think of and am going to give up and move on unless someone has a new idea. Oddly, it works well in ie7. Go figure.</p> <pre><code>&lt;!doctype html&gt; &lt;head&gt; &lt;style type="text/css"&gt; header, footer, nav, section, article { display: block; } body { font-size:1em; margin:0; padding:0; font-family: Verdana, Arial, Helvetica, Sans-Serif; color:#000; background:#ddd url(images/BG.jpg); } /*********** Start shrink wrapped and centered layout styles ************************/ #page { position:relative; overflow:hidden; } #container { float:left; position:relative; left:50%; } #content { float:left; position:relative; right:50%; } /*********** End shrink wrapped and centered layout styles ************************/ #content { border:solid 4px #bbb; } p { width:20em; background-color:red; float:left; } &lt;/style&gt; &lt;body&gt; &lt;div id="page"&gt; &lt;div id="container"&gt; &lt;div id="content"&gt; &lt;p&gt;p1&lt;/p&gt; &lt;p&gt;p2&lt;/p&gt; &lt;p&gt;p3&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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