2 个 div 在 html 页面居中
2 divs centered in html page
我试图使我的网页布局更好,所以我想在 html 页面的中央放置两个 div。我无权访问我的 css 文件。是否可以在没有 css 的 html 代码中将两个 div 在一页上居中?
这是我的代码:
<div style="width: 100%;">
<div style="; width: 100%;">
<h1 style="text-align: center;">This is Web Page Main tit</h1>
<div style="position: relative;
float: left;
left: 0px;
width: 470px;
height: 470px;
margin: 0 auto;
background-color: #828282">
<div><strong>Main Menu</strong></div>
</div>
<div style="position: relative;
float: left;
margin: 0 auto;
left: 0px;
width: 470px;
height: 470px;
background-color: #828282">
<p>oke and Managerial Tutorials</p>
</div>
</div>
<div style="background-color: #b5dcb3; clear: both;">Here text</div>
</div>
我知道有一个 <center>
html 标签可以试试,把它放在 </center>
你想要居中的 div 前后,或者如果你仍然可以改变你的内联样式,摆脱浮动,清除和定位并添加
div {
margin: auto;
}
你还有一个分号<div style=";width: 100%;">
两个 <div>
彼此相邻并在您的页面中心对齐:
<center>
<div>
<div style="display: inline-block">
<!-- div 1 contents -->
</div>
<div style="display: inline-block">
<!-- div 2 contents -->
</div>
</div>
</center>
我试图使我的网页布局更好,所以我想在 html 页面的中央放置两个 div。我无权访问我的 css 文件。是否可以在没有 css 的 html 代码中将两个 div 在一页上居中?
这是我的代码:
<div style="width: 100%;">
<div style="; width: 100%;">
<h1 style="text-align: center;">This is Web Page Main tit</h1>
<div style="position: relative;
float: left;
left: 0px;
width: 470px;
height: 470px;
margin: 0 auto;
background-color: #828282">
<div><strong>Main Menu</strong></div>
</div>
<div style="position: relative;
float: left;
margin: 0 auto;
left: 0px;
width: 470px;
height: 470px;
background-color: #828282">
<p>oke and Managerial Tutorials</p>
</div>
</div>
<div style="background-color: #b5dcb3; clear: both;">Here text</div>
</div>
我知道有一个 <center>
html 标签可以试试,把它放在 </center>
你想要居中的 div 前后,或者如果你仍然可以改变你的内联样式,摆脱浮动,清除和定位并添加
div {
margin: auto;
}
你还有一个分号<div style=";width: 100%;">
两个 <div>
彼此相邻并在您的页面中心对齐:
<center>
<div>
<div style="display: inline-block">
<!-- div 1 contents -->
</div>
<div style="display: inline-block">
<!-- div 2 contents -->
</div>
</div>
</center>