2013-12-15 38 views
0

我抬头看看如何在屏幕中间放置一个块,并且我读到必须指定宽度值和边距来自动调整。宽度和边距自动到中心不起作用

<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> 

我想块占据屏幕,居中,左,右suposed有15%的70%。如果我使用保证金余额:15%;同样的权利,然后块中心,但我仍然想知道为什么它不是居中时,我指定宽度和边距:汽车

回答

0

你不希望#CenteredBlock绝对定位。你想要它'居中'。所以,删除“位置:绝对”,一切都会正常工作。

+0

谢谢!它的工作 – Harlequin

+0

你很好。 – Viktor

+0

(因为我现在无法回答我的问题,所以我会发表评论)好吧,现在问题是使块从最上面的“最零”像素开始。现在它在块和浏览器栏之间留下了白色的空白! :P – Harlequin