Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

confused about wrapper div

Featured Replies

Hiieeee dear friends.smile.png I am new to web designing and learning how to use html divs and css layout techniques to layout webpages.I am having a problem about outer wrapper divs that is used by many web designers. What I want to do is that make a layout with a top header, a banner, main content area and then a footer. I want to fit all the contents of these sections that I have mentioned to be contained by a outer wrapper which is 960 px wide. But at the same time I want to make the background of the header and the footer take the full width of the browser. The problem is when I put the header and footer inside the 960px wide wrapper I am not able to make the header and footer backgrounds extend beyond 960px. So guys how do I achieve this layout by keeping the contents of the header,banner,content and footer inside the same 960 px outer wrapper and at the same time make the backgrounds of header and footer extend beyond 960 pixels. pleeez pleeez pleeez help me out guys.frown.png

This is my html code for the desired layout :

<div id="wrapper">

<div id="header">
header content...
</div>

<div id="banner">
banner content...
</div>

<div id="content">
main content...
</div>

<div id="footer">
footer content...
</div>

</div>

and this is the css :


#wrapper {
width:960px;
margin:0 auto;
}

#header {
background:#06C;
}

#banner {
background:#0C9;
}

#content {
background:#666666;
}

#footer {
background:#993333;
}

Hiieeee dear friends.smile.png I am new to web designing and learning how to use html divs and css layout techniques to layout webpages.I am having a problem about outer wrapper divs that is used by many web designers. What I want to do is that make a layout with a top header, a banner, main content area and then a footer. I want to fit all the contents of these sections that I have mentioned to be contained by a outer wrapper which is 960 px wide. But at the same time I want to make the background of the header and the footer take the full width of the browser. The problem is when I put the header and footer inside the 960px wide wrapper I am not able to make the header and footer backgrounds extend beyond 960px. So guys how do I achieve this layout by keeping the contents of the header,banner,content and footer inside the same 960 px outer wrapper and at the same time make the backgrounds of header and footer extend beyond 960 pixels. pleeez pleeez pleeez help me out guys.frown.png

 

This is my html code for the desired layout :

 

<div id="wrapper">

 

<div id="header">

header content...

</div>

 

<div id="banner">

banner content...

</div>

 

<div id="content">

main content...

</div>

 

<div id="footer">

footer content...

</div>

 

</div>

 

and this is the css :

 

 

#wrapper {

width:960px;

margin:0 auto;

}

 

#header {

background:#06C;

}

 

#banner {

background:#0C9;

}

 

#content {

background:#666666;

}

 

#footer {

background:#993333;

}

U could put both the header and footer outside the wrapper :)

use a wrapper class instead of id .. tht way u can use it repeatedly

 

like this

and make footer and header width 100%

<div id="header">
  <div class="wrapper">
header content...
  </div><!--wrapper-->
</div>


<div class="wrapper">

<div id="banner">
banner content...
</div>

<div id="content">
main content...
</div>



</div><!--wrapper-->

<div id="footer">
 <div class="wrapper">
footer content...
  
  </div><!--wrapper-->
</div>


.wrapper {
width:960px;
margin:0 auto;
}

#header {
width:100%;
background:#06C;
height:200px;
}

#banner {
background:#0C9;
}

#content {
background:#666666;
}

#footer {
width:100%;
height:50px;
background:#993333;
}

Edited by sash_oo7

You could also use two separate wrappers.

 

HTML

<div class="wrapper1">
	<div class="header">
		header content...
	</div>

	<div class="wrapper2">
		<div class="banner">
			banner content...
		</div>

		<div class="content">
			main content...
		</div>
	</div>

	<div class="footer">
		footer content...
	</div>
</div>

CSS

.wrapper1 {
	width:100%;
	text-align: center;
}

.wrapper2 {
	width: 960px;
	margin: 0 auto;
}

.header {
	background:#06C;
        width:100%;
}

.banner {
	background:#0C9;
        width: 100%; <-- this will make it take 960px wide from wrapper2
}

.content {
	background:#666666;
        width: 100%;
}

.footer {
	background:#993333;
        width: 100%;
}

Edited by junior

 

You could also use two separate wrappers.

 

HTML

<div class="wrapper1">
	<div class="header">
		header content...
	</div>

	<div class="wrapper2">
		<div class="banner">
			banner content...
		</div>

		<div class="content">
			main content...
		</div>
	</div>

	<div class="footer">
		footer content...
	</div>
</div>

CSS

.wrapper1 {
	width:100%;
	text-align: center;
}

.wrapper2 {
	width: 960px;
	margin: 0 auto;
}

.header {
	background:#06C;
        width:100%;
}

.banner {
	background:#0C9;
        width: 100%; <-- this will make it take 960px wide from wrapper2
}

.content {
	background:#666666;
        width: 100%;
}

.footer {
	background:#993333;
        width: 100%;
}

if u do it tht way how u going to center header and footer content without margin:auto ??

  • Author

 

use a wrapper class instead of id .. tht way u can use it repeatedly

 

like this

and make footer and header width 100%

<div id="header">
  <div class="wrapper">
header content...
  </div><!--wrapper-->
</div>


<div class="wrapper">

<div id="banner">
banner content...
</div>

<div id="content">
main content...
</div>



</div><!--wrapper-->

<div id="footer">
 <div class="wrapper">
footer content...
  
  </div><!--wrapper-->
</div>


.wrapper {
width:960px;
margin:0 auto;
}

#header {
width:100%;
background:#06C;
height:200px;
}

#banner {
background:#0C9;
}

#content {
background:#666666;
}

#footer {
width:100%;
height:50px;
background:#993333;
}

thanks a lot. This method really works best for me. using a multiple wrapper class instead of one wrapper really solves my problem. thnx again :santa_smiley:

  • 2 weeks later...

Simple and Easy

CSS CODE

 

.wrapper { width:960px; margin:0 auto;}

.header { width:100%; margin:0}

.content { width:960px; margin:0 auto}

.footer {width:100%; margin:0}

 

 

HTML CODE

 

<div class="header">

<div class="wrapper"><!-----Your Content --------------></div>

</div>

 

<div class="content"><!-----Your Content --------------></div>

 

<div class="footer">

<div class="wrapper"><!-----Your Content --------------></div>

</div>

 

 

 

---------> OR <--------------

 

CSS CODE

 

.wrapper { width:960px; margin:0 auto;}

.header,.content,.footer { width:100%; margin:0}

HTML CODE

 

<div class="header">

<div class="wrapper"><!-----Your Content --------------></div>

</div>

 

<div class="content">

<div class="wrapper"><!-----Your Content --------------></div>

</div>

 

<div class="footer">

<div class="wrapper"><!-----Your Content --------------></div>

</div>

 

 

 

 

By Xee Studios

Short and simple solution - the less code you use the smaller your file size, it's important to keep your code dry as in: dry = do not repeat yourself. and don't declare styles to elements that are already there by browser default such as width 100% and margin 0 on a block level element like <header> or <footer>.

Another thing - in css try to avoid ID's they have very high specificity and make them difficult to override - they also cannot be reused which means your code will not remain 'dry' once you begin adding more styles and elements etc. use ID's for JavaScript but not CSS

Anyway the code:

 

<div class="header">
   <div class="wrapper">
      header content...
   </div>
</div>
<div class="wrapper">
   <div class="banner">
      banner content...
   </div>
   <div class="content">
      main content...
   </div>
</div>
<div class="header">
   <div class="wrapper">
      footer content...
   </div>
</div>

 

 

.wrapper {
   width: 960px;
   margin: 0 auto;
}

 

Like I said you don't need to give the footer and header widths of 100% or margin 0, this is browser default for a div!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.