如何在html页面的正中央显示数据?

如何在html页面的正中央显示数据?,html,Html,在html页面的正中央显示数据 数据与各边的距离应相等?您可以使用表作为保存内容的元素的包装,并设置包装表的align='center'valign='middle'属性,表应适合页面。您可以使用位置为:relative的容器;保持居中元素的位置:绝对;为了获得垂直居中,代码如下: #parent { position: relative; width: 500px; height: 500px; background: #000; } #child {

在html页面的正中央显示数据


数据与各边的距离应相等?

您可以使用表作为保存内容的元素的包装,并设置包装表的align='center'valign='middle'属性,表应适合页面。

您可以使用位置为:relative的容器;保持居中元素的位置:绝对;为了获得垂直居中,代码如下:

#parent {
    position: relative;
    width: 500px;
    height: 500px;
    background: #000;
}

#child {
    position: absolute;
    width: 50%;
    height: 50%;
    background: #aaa;
    margin: auto;
    top: 0; left: 0; bottom: 0; right: 0;
}
CSS:

HTML:

请注意,您的内容必须具有特定的宽度px、%和em等,才能使用此方法居中

你可以这样做。 看


左边距:自动;右边距:自动;对于具有100%宽度的父级,将为you@serakfalcon. 但它不会在中间垂直对齐。水平对齐?垂直地这些维度已知吗?您是否意识到在页面上搜索类似html中心的内容会找到许多关于这个问题的答案?
.center {width:200px;margin:0px auto;}
<div class='center'>Your Content</div>
<div class="main">it is content</div>
<style type="text/css">
 .main{ top: 50%; left: 50%; position: absolute; margin-top: -50px;  margin-left: -100px;}
</style>