[英]Vertical Align Text After Font Icon
<div class="col-md-4">
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x blue"></i>
<i class="fa fa-wifi fa-stack-1x white"></i>
</span>
<h4 class="blue">Free wifi</h4>
</div>
How can I display h4
element on the right of the icon and vertically aligned?如何在图标右侧显示
h4
元素并垂直对齐? Should I float left the span
?我应该离开
span
吗?
One of the ways would be to use inline-block
display and middle align it - see demo below:一种方法是使用
inline-block
显示并中间对齐 - 请参见下面的演示:
.wrapper > * { display: inline-block; vertical-align: middle; } .blue { color: blue; } .white { color: white; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <div class="col-md-4 wrapper"> <span class="fa-stack fa-2x"> <i class="fa fa-circle fa-stack-2x blue"></i> <i class="fa fa-wifi fa-stack-1x white"></i> </span> <h4 class="blue">Free wifi</h4> </div>
Use CSS Flexbox .使用CSS 弹性盒。 Make a parent
<div>
that wraps icon and text into it (in my case its icon-holder
) and make it a flexbox container using display: flex
.创建一个父
<div>
将图标和文本包装到其中(在我的例子中是它的icon-holder
),并使用display: flex
使其成为一个 flexbox 容器。
Have a look at the snippet below:看看下面的片段:
.icon-holder { display: flex; /* Flex Container */ align-items: center; /* Vertically Align Content */ } .blue { color: #33b5e5; } span { color: #fff; } h4 { padding-left: 5px; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="col-md-4"> <div class="icon-holder"> <span class="fa-stack fa-2x"> <i class="fa fa-circle fa-stack-2x blue"></i> <i class="fa fa-wifi fa-stack-1x white"></i> </span> <h4 class="blue">Free wifi</h4> </div> </div>
Hope this helps!希望这可以帮助!
You can use display: flex
and can do something like below :您可以使用
display: flex
并且可以执行以下操作:
.col-md-4 { display: flex; align-items: center; } .blue { color: blue } .white { color: white; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <div class="col-md-4 wrapper"> <span class="fa-stack fa-2x"> <i class="fa fa-circle fa-stack-2x blue"></i> <i class="fa fa-wifi fa-stack-1x white"></i> </span> <h4 class="blue">Free wifi</h4> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.