[英]vertical align of an icon inside div
这里的JSFiddle演示:
http://jsfiddle.net/5q0nzrw8/
CSS:
.post-nav {margin: 20px 0;}
.post-nav-prev, .post-nav-next {float: left; padding: 10px; border: 1px solid #aaa; background: #fff; width: 298px;}
.post-nav-prev {text-align: left;}
.post-nav-next {text-align: right; margin-left: 20px;}
.post-nav-prev a, .post-nav-next a {font-family: Arial; font-weight: 500; font-size: 20px; -webkit-transition: all 0.4s ease; transition: all 0.4s ease; text-decoration: none;}
.post-nav-prev a:hover, .post-nav-next a:hover {color: #000;}
.post-nav-prev-icon, .post-nav-next-icon {}
.post-nav-prev-icon:before, .post-nav-next-icon:before {font-family: Arial; font-size: 28px; color: #aaa;}
.post-nav-prev-icon:before {float: left; content: '\00AB'; padding-right: 10px;}
.post-nav-next-icon:before {float: right; content: '\00BB'; padding-left: 10px;}
HTML:
<div class="post-nav">
<div class="post-nav-prev">
<span class="post-nav-prev-icon"></span>
<a href="#" rel="prev">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod.</a>
</div>
<div class="post-nav-next">
<span class="post-nav-next-icon"></span>
<a href="http://mydivision.net/2014/11/the-division-user-interface-styleguide-geleakt/" rel="next">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod</a>
</div>
</div>
我想要实现的是“»”和“«”是垂直居中的。
结果应如下所示:
不幸的是,我似乎太愚蠢了,所以我希望有人可以帮助我。 :)
使用display: table-cell;
& vertical-align: middle;
添加以下css
.post-nav-prev-icon,.post-nav-next-icon{
display: table-cell;
vertical-align: middle;}
.post-nav-prev a,.post-nav-next a{display: table-cell;}
并改变.post-nav-next
html如下
<div class="post-nav-next">
<a href="http://mydivision.net/2014/11/the-division-user-interface-styleguide-geleakt/" rel="next">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod</a>
<span class="post-nav-next-icon"></span>
</div>
post-nav {
margin: 20px 0;
}
.post-nav-prev, .post-nav-next {
float: left;
padding: 10px;
border: 1px solid #aaa;
background: #fff; width: 280px;
}
//使用float:left在你的div左边移动
.post-nav-prev {
text-align: left;
float: left
}
//使用float:向右移动你的div
.post-nav-next {
text-align: right;
margin-left: 20px;
float: right
}
.post-nav-prev a, .post-nav-next a {
font-family: Arial;
font-weight: 500; font-size: 20px;
-webkit-transition: all 0.4s ease;
transition: all 0.4s ease;
text-decoration: none;
}
.post-nav-prev a:hover, .post-nav-next a:hover {
color: #000;
}
.post-nav-prev-icon, .post-nav-next-icon {
}
.post-nav-prev-icon:before, .post-nav-next-icon:before {
font-family: Arial;
font-size: 28px;
color: #aaa;
}
.post-nav-prev-icon:before {
float: left;
content: '\00AB';
padding-right: 10px;
}
.post-nav-next-icon:before {
float: right;
content: '\00BB';
padding-left: 10px;
}
我将完全删除图标元素并直接应用于其父级( 在创建position:relative
)。
/*mini reset of box-sizing for current elements*/ .post-nav *{ -webkit-box-sizing:border-box; -moz-box-sizing:border-box; -ms-box-sizing:border-box; -o-box-sizing:border-box; box-sizing:border-box; } .post-nav {margin: 20px 0;} .post-nav-prev, .post-nav-next {float: left; padding: 10px; border: 1px solid #aaa; background: #fff; width: 298px;position:relative;} .post-nav-prev {text-align: left;padding-left:30px;} .post-nav-next {text-align: right; margin-left: 20px;padding-right:30px;} .post-nav-prev a, .post-nav-next a {font-family: Arial; font-weight: 500; font-size: 20px; -webkit-transition: all 0.4s ease; transition: all 0.4s ease; text-decoration: none;} .post-nav-prev a:hover, .post-nav-next a:hover {color: #000;} .post-nav-prev:before, .post-nav-next:before { font-family: Arial; font-size: 28px; color: #aaa; display:block; position:absolute; top:0; bottom:0; line-height:1.5em; height:1.5em; width:30px; margin:auto; text-align:center; } .post-nav-prev:before {left:0; content: '\\00AB';} .post-nav-next:before {right:0; content: '\\00BB';}
<div class="post-nav"> <div class="post-nav-prev"> <a href="#" rel="prev">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod.</a> </div> <div class="post-nav-next"> <a href="http://mydivision.net/2014/11/the-division-user-interface-styleguide-geleakt/" rel="next">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod</a> </div> </div>
尝试添加float:left; 和浮动:右边的prev / next,然后为其父级设置宽度:
.post-nav {margin:20px 0; width:700px;}
.post-nav-prev,.post-nav-next {float:left; 填充:10px; border:1px solid #aaa; 背景:#fff; width:298px;} .post-nav-prev {text-align:left; float:left;} .post-nav-next {text-align:right; margin-left:20px; float:right;}
.post-nav-prev a,。post-nav-next a {font-family:Arial; font-weight:500; font-size:20px; -webkit-transition:全部0.4s轻松; 过渡:全部0.4秒轻松; text-decoration:none;} .post-nav-prev a:hover,。post-nav-next a:hover {color:#000;}
.post-nav-prev-icon, .post-nav-next-icon {}
.post-nav-prev-icon:before, .post-nav-next-icon:before {font- family: Arial; font-size: 28px; color: #aaa;}
.post-nav-prev-icon:before {float: left; content: '\00AB'; padding-right: 10px;}
.post-nav-next-icon:before {float: right; content: '\00BB'; padding-left: 10px;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.