Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I add floating to a set of divs, all divs overlap and jump to the same position
    primarykey
    data
    text
    <p>I've been trying to practise building layouts for web pages and have run into a slight problem. When I try to float 1 or 2 div's, they all automatically jump to the same position and overlap. I'm sure I am missing something but I can't quite work out what it is.</p> <p>Now I have 3 div's set up inside my main div for example inside "box1" I have "header", "content" &amp; "footer".</p> <pre><code>&lt;div id="box1"&gt; &lt;div id-"header"&gt; &lt;div id="logo"&gt;&lt;img src="logo.png"/&gt;&lt;/div&gt; &lt;div id="apology"&gt;enter text here&lt;/div&gt; &lt;/div&gt; &lt;div id="content"&gt; enter content text &lt;/div&gt; &lt;div id="footer"&gt; footer &lt;/div&gt; </code></pre> <p></p> <p>Now... It is to my knowledge (I may most probably be wrong) that when you float an object it is relative to it's container?</p> <p>The two div's I am trying to float are "logo" and "apology". "logo" to the left and "apology" to make the page responsive to the size of the browser window (as you've probably guessed)</p> <p>As normal the boxes stack vertically one on top of the other but as soon as I add the float properties to #logo and #apology in my CSS file, every div seems to jump to the top of the browser and overlap.</p> <p>I have considered adding margins and heights to the div's in my css to position the "content" and "footer" boxes to where I want them but had deleted those entries due to it making them both fixed to where I had set the margins so when I resized the browser as normal my two floating divs would meet and arrange themselves one under the other however they would then overlap the "content" again.</p> <p>I'm at the point of pulling my hair out now so any help would be much appreciated, especially as I've managed to turn a simple question into an essay.</p> <p>The full html and css are below so you can test or see my errors</p> <p>Many thanks, Matthew</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Welcome&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="stylesheet.css"&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="box1"&gt; &lt;div id-"header"&gt; &lt;div id="logo"&gt;&lt;img src="logo.png"/&gt;&lt;/div&gt; &lt;div id="apology"&gt;enter text here&lt;/div&gt; &lt;/div&gt; &lt;div id="content"&gt; enter content here &lt;/div&gt; &lt;div id="footer"&gt; footer &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>CSS</p> <pre><code>#box1 { max-width: 1024px; border: solid black 1px; margin-left: auto; margin-right: auto; display:block; -webkit-box-orient: vertical; } #header { display:block; -webkite-box-orient: vertical; } #logo { float: left; padding: none; display:block; } #apology { float: right; display:block; } #content { background:url('contentbg.jpg') center; background-size: cover; display: block; border: 1px black solid; text-align: left; } </code></pre> <p>Fiddles:</p> <p><a href="http://jsfiddle.net/h9QX5" rel="nofollow">Html without CSS</a></p> <p><a href="http://jsfiddle.net/X59tp" rel="nofollow">Html with CSS</a></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