Html 使用css对齐中心

Html 使用css对齐中心,html,css,Html,Css,我有一个带有div标记的html文件,该标记中有一些文本。我想调整文本正中间的div,也正中间的div页的任何决议。我用margin:0 auto尝试了一下,然后它显示在顶部中间,但在垂直方向上它不显示在中间。div需要这样的CSS,具体取决于HTML的其余部分: margin-left: auto; margin-right: auto; text-align: center; 这将使div在其容器的中心对齐,并使其中的文本也与中心对齐 编辑-我刚刚注意到您也希望垂直居中分割。有很多方法可以

我有一个带有
div
标记的html文件,该标记中有一些文本。我想调整文本正中间的div,也正中间的div页的任何决议。我用
margin:0 auto
尝试了一下,然后它显示在顶部中间,但在垂直方向上它不显示在中间。

div需要这样的CSS,具体取决于HTML的其余部分:

margin-left: auto;
margin-right: auto;
text-align: center;
这将使div在其容器的中心对齐,并使其中的文本也与中心对齐


编辑-我刚刚注意到您也希望垂直居中分割。有很多方法可以做到这一点,一个快速的Google会显示出来,比如这个方法:

div需要这样的CSS,这取决于HTML的其余部分:

margin-left: auto;
margin-right: auto;
text-align: center;
这将使div在其容器的中心对齐,并使其中的文本也与中心对齐


编辑-我刚刚注意到您也希望垂直居中分割。有很多方法可以做到这一点,一个快速的谷歌会显示出来,比如这个方法:

也许你可以试试这个,

也许你可以试试这个,

要调整你的div,请使用以下代码:

margin-left: auto;
margin-right: auto;
text-align: center;
要使文本位于div中间,请使用以下代码:

margin-left: auto;
margin-right: auto;
text-align: center;

要调整div,请使用以下代码:

margin-left: auto;
margin-right: auto;
text-align: center;
要使文本位于div中间,请使用以下代码:

margin-left: auto;
margin-right: auto;
text-align: center;

margin auto 0
仅当您将
width
赋予
div
时才起作用<代码>文本对齐:居中将对齐中间的文本。

页边距自动0
仅当您将
宽度
指定给
div
时才起作用<代码>文本对齐:居中将对齐中间的文本。

给你:。

给你:。

你必须用css设置容器div,如下所示:

div{
    margin: 0 auto; /*= the 0 sets the top and bottom margin to zero and the auto centers the div =*/
    width: 940px;   /*= the width is a must have but can be set to the size you need =*/
    text-align: center; /*= use this if you want to center the text inside the div =*/
}

必须使用css设置容器div,如下所示:

div{
    margin: 0 auto; /*= the 0 sets the top and bottom margin to zero and the auto centers the div =*/
    width: 940px;   /*= the width is a must have but can be set to the size you need =*/
    text-align: center; /*= use this if you want to center the text inside the div =*/
}