I am trying to create a HTML layout and I have created a number of elements and given them a border etc in my CSS. I am trying to have the main 'Wrapper' centered so everything that goes inside this element are also centered.
I have tried everything, margin, align, absolute etc and nothing is working. My stays situated in the top left corner of my page.
This is my index page where the elements are:
<!--#include file ="inc.heads.asp"-->
<html>
<head>
</head>
<body>
<div id ="divWrapper">
<div id ="divHeader">
<img src="Images/title.png">
<br>
<div id ="divNavBar">
<br>
<div id ="divContent">
</div>
</div>
</div>
</div>
</body>
</html>
and this is my CSS:
body {
background-color: #300;
}
#divWrapper {
margin: 0 auto;
width: 800px;
}
#divHeader {
width: 500px;
border-style: inset;
border-color: #COCOCO;
background-color: #707070;
padding: 5px;
}
#divNavBar {
width: 500px;
border-style: inset;
border-color: #COCOCO;
background-color: #707070;
padding: 5px;
}
#divContent {
float: left;
width: 500px;
border-style: inset;
border-color: #COCOCO;
background-color: #707070;
padding: 5px;
}
If someone could possibly shed some light on why none of the things I have tried work and what a possible solution could be.
Thanks!
Should do the trick.
Seriously what is the point of all those wrappers? Just do this:
Just add
margin: 0 auto
to the contents of#divWrapper
:For example, add to your CSS:
If you only want the
div
elements to be centered, use:You can see a working demo here > http://jsfiddle.net/gu7Sr/
Also, as a side note, try to avoid using
<br />
for creating your layout. It won't scale well and you'll have a tough time redesigning in the future!More just a comment to BenM's answer, but I don't have the reputation to comment yet. Pretty sure just:
will do the trick by itself.
I think this is what you want. Link : http://codepen.io/anon/pen/Ihzxp
and