Hello

I am using a 3 column layout for which the css is as below

mysbody {
margin:0;
padding:0;
background:#cecece;
}
#wrap {
width:1024px;
margin:0 auto;
background:#fff;
}
#header {
width:1024px;
height:200px;
}
#left {
width:200px;
float:left;
}

#leftbarheader {
width:160px; height:20px; padding-top:7px;
 
}

#leftbarheader2 {
width:160px; height:20px; padding-top:7px;
 
}

#leftbarheader3 {
width:160px; height:20px; padding-top:7px;
 
}


#leftbar {
width:160px;
float:left;
}

#leftbar2 {
width:160px;
float:left;
}

#leftbar3 {
width:160px;
float:left;
}



#middle {
width:610px;
float:left;
}
#right {
width:160px;
float:left;
}

#rightbarheader {
width:160px; height:20px; padding-top:7px;
 
}

#rightbarheader2 {
width:160px; height:20px; padding-top:7px;
 
}

#rightbarheader3 {
width:160px; height:20px; padding-top:7px;
 
}


#rightbar {
width:160px;
float:left;
}

#rightbar2 {
width:160px;
float:left;
}

#rightbar3 {
width:160px;
float:left;
}



#footer {
width:1024px;
height:30px;
}
.clear {
clear:both;
}

BAsically, there is a section where user can change the bg color for the entire page, and this changes the background of the page, ie of the div named 'wrap;. But in actuality, only the bg color for the top portion (corresponding to the header) is being changed

Given below is the code which uses the CSS above:

<div id="mysbody">
      			<div id="wrap">
					<font color="#000000">	<div id="header">



												  		      header stuff
						</div>



						<div id="left">



									            		<div id="leftbar">
							                              <div id="leftbarheader">Title 1 </div>
							                              <a href="link.html">example link</a><br />
							                              <a href="link.html">example link</a><br />
							                              <a href="link.html">example link</a><br />
							                              <a href="link.html">example link</a><br />
							                           </div>
									            		<div id="leftbar2">
									                	      <div id="leftbarheader2">  Title 2 </div>

												  			      <a href="link.html">example link</a><br />
												  			      <a href="link.html">example link</a><br />
												  			      <a href="link.html">example link</a><br />
												  			      <a href="link.html">example link</a><br />

													    </div>

														<div id="leftbar3">

									                		   <div id="leftbarheader3">  Title 3 </div>

												  	    		  <a href="link.html">example link</a><br />
												  	    		  <a href="link.html">example link</a><br />
												  	    		  <a href="link.html">example link</a><br />
												  	    		  <a href="link.html">example link</a><br />


											  	        </div>
						 </div>


						<div id="middle">
												  	      This is fake text to give the impression of an average size paragraph which would appear in a normal web page. This text should be replaced with real paragraphs in a normal web page. This is fake text to give the impression of an average size paragraph which would appear in a normal web page. This text should be replaced with real paragraphs in a normal web page.
						</div>
						<div id="right">
									                    <div id="rightbar">

													    	<div id="rightbarheader">  Title 1 </div>

												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	   <a href="link.html">example link</a><br />
													    </div>

									                    <div id="rightbar2">


									                       <div id="rightbarheader2">  Title 2 </div>

												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	   <a href="link.html">example link</a><br />


													    </div>

									                    <div id="rightbar3">

									                       <div id="rightbarheader3">  Title 3 </div>

												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	    <a href="link.html">example link</a><br />
												  	    	   <a href="link.html">example link</a><br />

											  	  	    </div>
						</div>
								</font>

						</div>
  				</div>

Someone can please tell me what is wrong in the code
Thanks

Regards
Arvind

Dani AI

Generated

Short summary and extra options

This thread shows the classic case where a group of floated columns leaves the parent’s background appearing only behind the header. ’s suggestion fixed the immediate problem and confirmed it worked. For readers who want a clearer, more maintainable approach (and modern alternatives), the following covers other ways to make a wrapper “contain” floated children and a few practical tips.

A small, widely compatible clearfix (no extra markup) — add a pseudo-element that clears floats:

.clearfix::after {
  content: "";
  display: table;
  clear: both;
}

Make the wrapper a formatting root (simpler, modern):

#wrap {
  display: flow-root;
}

Or move away from floats entirely and use Flexbox for a stable 3-column layout that adapts to different widths:

.columns { display: flex; gap: 16px; align-items: flex-start; }
.left, .right { width: 160px; }
.middle { flex: 1; }

Practical tips and cautions

  • Use box-sizing: border-box site-wide so padding/border don’t break your width math.
    *, *::before, *::after { box-sizing: border-box; }
  • Prefer semantic elements (header, main, aside, footer) and avoid deprecated tags.
  • If you need to debug: open DevTools, toggle temporary background colors or outlines on the wrapper and columns, and inspect computed heights to confirm whether the wrapper is enclosing its children.
  • Be careful with solutions that affect overflow: some create scrolling or clip content; choose one that fits your layout needs.

These options give a cleaner, more future-proof layout than relying on float behavior alone and make the page easier to maintain and adapt.

Recommended Answers

All 2 Replies

I'm not totally clear on the issue, but I suspect you are expecting the modified background color to affect the entire wrap container; if that's the case, I would add overflow: hidden; to your #wrap selector:

#wrap {
     overflow: hidden;
}

I also noticed that the first line in your CSS is attempting to select "mysbody", which isn't a page element, but a div ID - my guess is your copy/paste just missed the preceding "#"...

Also as another aside, you might want to consider removing your <font> tag immediately after your wrap div; a better approach would be to utilize CSS for this - additionally, #000 is your default text color anyway.

commented: gave correct answer ! +1

Hello scottloway,

Thanks for your answer, I was expecting the modified background color to affect the entire wrap container; now with your code it works perfectly

Regards
Arvind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.