您的位置:首页 > Web前端 > CSS

css样式设置(居中)普通

2015-03-30 15:59 162 查看
1、水平居中

<style>
div.txtCenter{
text-align:center;
}
</style>

2、宽度固定居中显示

<style>
div{
border:1px solid red;/*为了显示居中效果明显为 div 设置了边框*/

width:500px;/*定宽*/
margin:20px auto;/* margin-left 与 margin-right 设置为 auto */
}

</style>

3、设置垂直高度

父元素高度确定的单行文本的竖直居中的方法是通过设置父元素的 height 和 line-height 高度一致来实现的。

<style>
.container{
height:100px;
line-height:100px;
background:#999;
}
</style>

4、设置宽度不起作用时,如
position:float;  可改为
absolute 宽度会显示出来


<style>
.container a{
position:absolute;
width:200px;
background:#ccc;
}
</style>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  css样式