April 8, 201412 yr 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; }
April 8, 201412 yr 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 April 8, 201412 yr by Jack
April 8, 201412 yr 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 April 8, 201412 yr by rbrtsmith
April 8, 201412 yr 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.
April 12, 201412 yr 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/
April 12, 201412 yr 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/ Ah thanks for clearing that up. My bad, must have got confused ;3
Create an account or sign in to comment