...

View Full Version : Really simple html problem



garabildi
02-25-2011, 03:49 PM
or so I imagine...

I want to insert a transparent background image into the main #content of my page.

The #content contains two divs (#contentLeft and #contentRight) before being closed off. However, because I don't want to set the height of the #content, I can't see any image I insert. I would have though that the #content would automatically stretch to incorporate whatever height dimensions #contentLeft and #contentRight use but this obviously isn't the case.

The only way I can think of a getting around this (other than setting the height) is to create another div which incorporates #content, #contentLeft, #contentRight and probably #footer. This would make a inserting a rounded edge image into #footer problematic (unless I used a jpeg that had the background coulour matched with the body background colour).

Hope my question is clear.



<body>
<div id="wrapper">
<div id="banner">
</div>
<div id="nav">
<ul>
<li><a href="index.html" title="Click for Home">Home</a></li>
<li><a href="about.html" title="Click for About">About</a></li>
<li><a href="news.html" title="Click for News">News</a></li>
<li><a href="involved.html" title="Click for get Involved">Get Involved</a></li>
<li><a href="services.html" title="Click for Services">Services</a></li>
<li><a href="links.html" title="Click for Links">Links</a></li>
</ul>
</div>
<div id="content">
<div id="contentLeft">
</div>
<div id="contentRight">
</div>
</div>
<div id="footer">
</div>
</div>
</body>

teedoff
02-25-2011, 03:54 PM
I think we need to see more than a snippet of your code. Better would be a live link to your site.

VIPStephan
02-25-2011, 03:56 PM
I suppose you need to read on containing floats (http://complexspiral.com/publications/containing-floats/). Specifically, the content div is collapsing to zero when you float those child divs. You need to clear the float inside that content div and an easy way to do this is:



#content:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}


IE7 and 6 don’t understand the :after pseudo class but incorrectly contain a float if the element has layout (http://www.satzansatz.de/cssd/onhavinglayout.html). For this you can apply height: 1% to the container div.

Excavator
02-25-2011, 03:58 PM
Hello garabildi,
An even easier way of clearing floats adding overflow: auto; to the element that contains the floats.

See here (http://www.quirksmode.org/css/clearing.html) for a description of how that works.

garabildi
02-25-2011, 06:12 PM
Spot on, Excavator!

I've tested it in a few browsers (latest FF, Opera and Win 8) and the more concise version seems to work fine. But I am a little worried that the design view of Dreamweaver (CS4) doesn't seem able to handle this fix. Instead of two child divs appearing within the parent they appear to the left. In other words, I've got a site that stretches 1600px across the Design view. #content = 800px, #contentLeft = 400px, #contentRight = 400px. I'm hoping that this is just Dreamweaver.

Excavator
02-25-2011, 06:51 PM
the design view of Dreamweaver (CS4) doesn't seem able to handle this fix.

DW design view is a joke. It doesn't render code like any known browser. Don't depend on it at all, much better to use code view and F12.

teedoff
02-25-2011, 06:57 PM
Live view does a fair job at rendering, but as Excavator says, I would never rely on DW to render code. Always view code in live browsers.

Design view isnt really meant as a preview of what code will look like in a browser. For example, any server-side code wont be parsed in design view alone. Live view will though.

garabildi
02-25-2011, 06:59 PM
Cheers guys.

Yeah, I know it's pretty crap (it also appears funny in Live version). I guess I'm just used to design and live view rendering something fairly close to what you see in a browser. But if this is just a case of design view having a conniption, as opposed to some rotten coding on my part (which is HIGHLY likely give my experience level), I'm happy.

VIPStephan
02-25-2011, 10:58 PM
An even easier way of clearing floats adding overflow: auto; to the element that contains the floats.

Sorry to chime in so late. This is definitely true but I have to add that this isn’t a solution for every case as it may cause issues if you are positioning or otherwise moving elements outside of the boundaries of that element. The :after rule may be a little more elaborate but doesn’t cause issues in that respect.

Another alternative just comes to mind: Create a block formatting context for the content div by floating it itself (applying a 100% width). This will also cause interior floats to be contained and doesn’t cause the problems the overflow solution does.

garabildi
02-26-2011, 05:51 PM
Thanks, I'll keep this in mind next time such issues arise.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum