html - 如何垂直对齐不同高度的网页字体和文本

标签 html css

有两个按钮,我想在其中添加图标和文本。

<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>

这是 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;
}

我从按钮类中删除了样式内容。目前它们不是垂直居中的,如屏幕截图所示。

有没有人有什么想法?

enter image description here

最佳答案

删除其他行高,只添加显示 block 上的行高

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

关于html - 如何垂直对齐不同高度的网页字体和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26326959/

相关文章:

javascript - 当我单击具有相同类的列表中的按钮时,在顶部元素中添加类 - Jquery

javascript - 表 - 固定标题,可滚动主体,最强大/最简单的解决方案?

javascript - 我希望更新未读消息的数量,并在用户收到新消息时播放通知声音。我使用 PHP、MySql、Javascript

html - 如何在我的案例中定位我的链接?

jquery - 如何在所有方向上移动元素?

javascript - 在 JavaScript 中向选择添加选项不更新

codeigniter 新页面中的 Css

html - 使用 Flexbox 的等高卡片

javascript - css Accordion 向右箭头和向下箭头无法正常工作

html - 为什么IE7没有背景图片?