如何在页面中心设置 div 位置,大小为 80%/80%。
UPD:保证金:0自动;有效,但仅适用于水平对齐。而且我还需要垂直。
本页讨论了使用 css 实现垂直居中的一些不同方法。我以前成功地使用过方法 2,但我认为所有这些充其量都是 hack。
设置固定宽度和自动边距。
<style type="text/css">
#center {
width:300px;
margin-left:auto;
margin-right:auto;
}
</style>
<body>
<div id="center"></div>
</body>
这可以满足您的要求,但它并不漂亮。
<div style="margin: 0 auto;width:80%;height:80%;">
This will probably not work for you however because you did not provide code
</div>