【发布时间】:2014-01-02 20:05:35
【问题描述】:
我查看了如何在屏幕中间将块居中,我读到我必须将宽度指定为一个值,并将边距指定为自动。
<head>
<style>
#CenteredBlock {
display: block;
position: absolute;
visibility: visible;
height: 70px;
width: 70%;
margin-left: auto;
margin-right: auto;
border-top-style: dotted;
border-right-style: dotted;
border-bottom-style: dotted;
border-left-style: dotted;
border-top-color: #000;
border-right-color: #000;
border-bottom-color: #000;
border-left-color: #000;
padding: 0%;
}
</style>
</head>
<body>
<div class="CenteredBlock" id="CenteredBlock"> Test </div>
</body>
我希望块占据屏幕的 70%,居中、左和右应该有 15%。如果我使用 margin-left: 15%;和右边一样,然后块居中,但我仍然想知道为什么当我指定宽度和边距时它不居中:auto
【问题讨论】:
标签: css width block center margins