CSS 水平对齐
在 CSS 元素。
使用 margin 对齐
设置为 "auto"元素。
注释:明了 !DOCTYPE margin:auto 在 IE8 效的。
auto素:
实例
.center
{
margin-left:auto;
margin-right:auto;
width:70%;
background-color:#b0e0e6;
}
提示: 100%有效果。
使用 position 和右对齐
位:
实例
.right
{
position:absolute;
right:0px;
width:300px;
background-color:#b0e0e6;
}
注释:
容性问题
对 <body> 的差异。
当使用 position 属性时,IE8 案例中是 <div class="container"> !DOCTYPE IE8 侧增加 17px 使用 position 始终设置 !DOCTYPE 声明:
实例
body
{
margin:0;
padding:0;
}
.container
{
position:relative;
width:100%;
}
.right
{
position:absolute;
right:0px;
width:300px;
background-color:#b0e0e6;
}
容性问题
对 <body> 的差异。
当使用 float 属性时,IE8 果省略 !DOCTYPE IE8 侧增加 17px 使用 float 始终设置 !DOCTYPE 声明:
实例
body
{
margin:0;
padding:0;
}
.right
{
float:right;
width:300px;
background-color:#b0e0e6;
}