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.

Header and Footer 100% width

Featured Replies

Hi guys!

 

I want to know what is the best way to give my header and footer a 100% width just so I can fit a background image (repeat-x) for both.

I have an idea of how to do it but I want to confirm with you boffins if this method is ok to go ahead with...

I am also having problems viewing the outcome on dreamweaver design view. Everything is shifted to the left. Am I doing something wrong or is dreamweaver a bit dodgy in that department?

Please guys, any help would be nice. Fixed layouts is all I've done in the past and now I'm experimenting with different styles.

 

eg.

 

HTML:

<html>
<head>
<title>100% Header and Footer</title>
</head>
<body>

<div id="headerWrap">
	<div id="header">Header</div>
</div>

<div id="contentWrap">
	<div id="content">Content</div>
</div>

<div id="footerWrap">
	<div id="footer">Footer</div>
</div>

</body>
</html>

CSS:

* {
	padding:0;
	margin:0;
	}
	
#headerWrap {
	width:100%;
	background-color:#;
	}
#header {
	width:940px;
	margin:0 auto;
	height:200px;
	background-color:#777;
	}

#contentWrap {
	width:100%;
	background-color:#eee;
	}
#content {
	width:940px;
	margin:0 auto;
	min-height:600px;
	background-color:#ddd;
	}

#footerWrap {
	width:100%;
	background-color:#;
	}
#footer {
	width:940px;
	margin:0 auto;
	height:300px;
	background-color:#777;
	}

 

That looks ok to me, but do you need fixed heights on your content divs?

 

You could do something like this instead http://jsfiddle.net/jack_pallot/427A3/ this will allow you to reuse containers, so that you don't have to create a new one for each element.

Edited by Jack

those div's are block level elements so they will automatically span to 100% width of thier container (in this case the body) so don't require the width 100% attribute.

 

Also if you're using html5 you should look into using the <header> and <footer> tag, they visially behave exactly the same way as a div but have more semantical meaning. Another point - try to get in the habit of using classes as opposed to ID's, in a bit project you will likely run into specificity issues. Not to mention using classes allows your css modules to be reusable.

 

just my 2p. :)

Edited by rbrtsmith

Just to add on to what the above said.

 

Try getting in to the habit of using classes (. instead of #) as appose to ID's as they load quicker. ID's are best kept for use with javascript.

Just to add on to what the above said.

 

Try getting in to the habit of using classes (. instead of #) as appose to ID's as they load quicker. ID's are best kept for use with javascript.

 

FYI: ID's are faster than classes. It's insignificant but hey ho. Still, spot on, ID's do not belong in a stylesheet. See http://csswizardry.com/2011/09/writing-efficient-css-selectors/

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.