[英]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.