【发布时间】:2014-02-09 20:56:11
【问题描述】:
我正在尝试使 id="center" 的 div 在 body 标记内垂直和水平居中,而不会扭曲内容的位置:M、cicle div 和 Coming Soon... 文本。即使它应该是一件简单的事情,也无法真正让它发挥作用..
HTML:
<body>
<div id="center">
<div class="circle"><div>M</div></div>
<h2>Coming soon...</h2>
</div>
</body>
CSS:
* {
margin: 0;
padding: 0;
font-family: futura;
}
body {
height: 100%;
width: 100%;
background-color: black;
}
h2 {
color: #f6c003;
font-family: serif;
font-style: italic;
font-weight: 400;
font-size: 0.9em;
margin-top: 10px;
}
.circle {
text-align: center;
width: 50px;
height: 50px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #f6c003;
}
.circle div {
float:left;
width:50px;
padding-top:25px;
line-height:1em;
margin-top:-0.5em;
text-align:center;
color:black;
font-style: bold;
font-weight: 700;
font-family: serif;
font-size: 2.5em;
}
【问题讨论】:
-
询问如何使占据整个宽度的元素居中是没有意义的……