Horisontal Alignment of Elements
This article would tell you how to horizontalize page elements.
There can be a few cases. Let’s consider all of them:
Horizontal centering of a block with fixed weight
<div id=”wrapper”>
<div id=”main”>
Content
</div>
</div>#wrapper{
width:100%;
}
#main {
margin:0 auto;
width:100px;
}
Alternative:
Attention: when size of browser window is less than size of centered DIV, element will be out of the screen.
html, body{
padding: 0;
margin: 0;
width:100%;
height:100%;
}
#container{
position: absolute;
left: 50%;
width: 400px;
margin-left: -200px;
}
Horizontal alignment of a block with optional width
<div id=”wrapper”>
<div id=”outer”>
<div id=”main”>
Content
</div>
</div>
</div>#wrapper{
width:100%;
}
#outer{
float:left;
left:50%;
position:relative;
}
#main {
left:-50%;
position:relative;
}
Horizontal alignment of a string element
You can make this element block element and use one of the solutions above.
#main{
display:block;
}