Forum Moderators: not2easy

Message Too Old, No Replies

Problem with css layout

css layout

         

avlisodraude

3:48 pm on Sep 11, 2009 (gmt 0)

10+ Year Member



Hi,
I have been trying to develop my own CSS layout, but I have been faced with the following problem. When I set a container DIV for the content and latter I try to set background-color and other CSS styles this seems no to wrap the internal content.
Here I show you the general layout. The problem are present with the content DIV.
Thanks in advance,

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gelderse Aanpak</title>
<style type="text/css">
*{ margin:0; padding:0; border:0; }
#header{ width:960px; border:1px solid #000; margin:0 auto; background-color:#FC3;}
#content{ width:960px; border:1px solid red; margin: 0 auto; }
#footer{ width:960px; border:1px solid yellow; margin:0 auto; clear:both; background-color:#999;}
#left{ width:200px; position:relative; float:left; border:1px solid blue; background-color:#C9C;}
#right{ width:750px; position:relative; float:right; border:1px solid green; background-color:#FCF;}
body{background-color:#000;}
</style>
</head>

<body>

<div id="header">
<h1> header </h1>
</div><!-- end of header -->

<div id="content">

<div id="left">
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
</div><!-- end of left -->

<div id="right">
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
<p>Any content that does not fit in a fixed-width or -height box causes the box to expand to fit the content rather than letting the content overflow.<br />
</p>
</div><!-- end of right -->

</div><!-- end of content -->

<div id="footer">
<p>footer data</p>
</div><!-- end of footer -->

</body>
</html>

D_Blackwell

4:30 pm on Sep 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not seeing your issue, or am misunderstanding the question. Someone else will have to address that.

However:

1) You will probably need to declare a full, valid DTD for {margin: 0 auto;} to work in IE.

2) It might be simpler to use a wrapper <div> around everything:
#wrapper {
margin: 0 auto;
width: 960px;
}

This would allow you to remove the declarations from #header, #content, and #footer - putting them in one place and making the other IDs a little neater and easier to read later.

Also - what do the <br /> do for you at the end of each <p>? If you are 'creating space' or some such, then padding-bottom: on the <p> would be a much cleaner approach.? Can say without understanding the purpose.

swa66

5:21 am on Sep 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see any fixed height, but maybe what you're trying to state is that your floated children don't stretch the height of their parent ?

That's as intended.

If you want it differently: add a <br class="clear" /> inside the parent after the floated columns. and give it "clear:both;" in the css.
Or lookup clearfix and use that technique (but be extra careful of the hacks many of the examples you'll find contain).