简体   繁体   English

如何垂直对齐Webfont和不同高度的文本

[英]How can I vertically align a webfont and text of different heights

Got two buttons that I want to have an icon and text in. 我得到了两个要在其中添加图标和文字的按钮。

<a href="#">
    <div class="button">
        <i class="flaticon-tools6"></i>
        <p>View all services</p>
    </div>
</a>

<a href="#">
    <div class="button">
        <i class="flaticon-phone16"></i>
        <p>Get a quote</p>
    </div>
</a>

Here's the CSS 这是CSS

.button .flaticon-phone16,
.button .flaticon-tools6 {
font-size: 30px;
line-height:42px;
}

.button p {
display: inline;
line-height:42px;
margin: 0px;
}

.button {
font-size:15px;
font-weight:bold;
font-style:normal;
line-height: 42px;
height:42px;
width:100%;
text-decoration:none;
text-align:center;
padding: 0;
}

I removed the styling stuff from the button class. 我从按钮类中删除了样式内容。 Currently they are not vertically centered, as visible in this screenshot. 当前,它们未垂直居中,如此屏幕截图所示。

Does anyone have any ideas? 有人有什么想法吗?

在此处输入图片说明

删除另一行高,仅在显示块上添加行高

.button p {display: block; margin: 0px; line-height: 42px; }

You can use display: table-cell combine with vertical-align: middle : 您可以使用display: table-cell结合vertical-align: middle

 a { width: 100%; display: table; } .button .flaticon-phone16, .button .flaticon-tools6 { font-size: 30px; } .button p { margin: 0px; } .button { display: table-cell; font-size:15px; font-weight:bold; font-style:normal; line-height: 42px; height:42px; width:100%; text-decoration:none; text-align:center; padding: 0; } 
 <a href="#"> <div class="button"> <i class="flaticon-tools6"></i> <p>View all services</p> </div> </a> <a href="#"> <div class="button"> <i class="flaticon-phone16"></i> <p>Get a quote</p> </div> </a> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM