CSS如何水平居中一个div [英] CSS How to center a div horizontally

查看:151
本文介绍了CSS如何水平居中一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力水平居中一个div。我有下面的代码来垂直和水平居中我的div在身体标记,但似乎只是垂直的作品。我怎样才能让水平片能够工作。提前致谢。

  body 
{
background-color:#081418;
font-size:.75em;
font-family:Verdana,Helvetica,Sans-Serif;
保证金:0;
padding:0;
颜色:#696969;
text-align:center;
}

.OuterRim
{
border:5px solid#99D7C0;
身高:97%;
宽度:85%;
/ *居中对齐* /
display:block;
text-align:left;
margin:0px auto;



解决方案

本教程中的一个视图可以学习如何执行此操作。你需要有一个固定宽度的元素。这可以用css或jquery完成。


I am working on centering a div horizontally. I have the following code to center my div in the body tag both vertically and horizontally, but seems just the vertical piece works. How can I get the horizontal piece to work as well. Thanks in advance.

body
{
    background-color: #081418;
    font-size: .75em;
    font-family: Verdana, Helvetica, Sans-Serif;
    margin: 0;
    padding: 0;
    color: #696969; 
    text-align: center;
}

.OuterRim
{
    border:5px solid #99D7C0;
    height: 97%;
    width: 85%;
    /*center aligning*/ 
    display: block;
    text-align: left;
    margin: 0px auto;

}

解决方案

Take a look here at this tutorial to learn how to do it. You need to have an element with a fixed width. This can be done with css or jquery.

这篇关于CSS如何水平居中一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆