【发布时间】:2018-08-29 18:10:20
【问题描述】:
我想将四个链接放在一个 div 中。
这是我到目前为止所做的:jsfiddle
HTML:
<div id="menu">
<section>
<a class="top" href="#">Top</a>
<a class="left" href="#">Left</a>
<a class="right" href="#">Right</a>
<a class="bottom" href="#">Bottom</a>
</section>
</div>
CSS:
#menu {
width: 200px;
height: 200px;
border: 1px solid #000;
background: #eee;
position: relative;
padding: 10px;
}
#menu>section {
position: absolute;
text-align: center;
width: 200px;
}
#menu a {
display: block;
vertical-align: middle;
height: 20px;
}
#menu .left {
float: left;
height: 160px;
}
#menu .right {
float: right;
}
#menu .bottom {
clear: both;
}
问题在于浮动元素没有按应有的方式垂直居中。我希望 left 和 right 元素位于中间而不是顶部。
【问题讨论】:
标签: html css positioning alignment