gpt4 book ai didi

html - 如何在盒子/容器中水平和垂直居中对齐文本?

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:17 24 4
gpt4 key购买 nike

我正在尝试创建一个如下所示的网页:

Download page

我使用 bootstrap 并创建行以将三个下载选项彼此对齐。然后,我在这些行中创建了容器(以复制框)并将文本和下载图标水平居中对齐。不幸的是,我不确定如何在容器中垂直居中对齐文本和图标。任何人都可以帮忙吗?我当前的设计如下所示:

Current design

我的代码如下:

.download {
font: Verdana, Helvetica, Arial, sans-serif;
color: RGB(112, 112, 112);
font-size: 18px;
text-align: center;
padding: 5px;
}

.download:hover {
color: rgb(227, 111, 30);
cursor: pointer;
}

#download-icon {
font-size: 80px;
float: left;
}

.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
}
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<p class="download"> Download list of charities that have <b> not submitted </b> data yet </p>
</div>
</div>
</div>
</div>

编辑:感谢大家的回答!我真的很感激他们。对我来说,它通过简单地调整我的内容边界类来工作:

.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
display: flex;
align-items: center;
/* vertical center */
}

最佳答案

您不需要使用 FlexBox 使事情复杂化。请使用类似这样的表格布局或 line-heightvertical-align 组合:

.download {
font: Verdana, Helvetica, Arial, sans-serif;
color: RGB(112, 112, 112);
font-size: 18px;
text-align: center;
padding: 5px;
}

.download:hover {
color: rgb(227, 111, 30);
cursor: pointer;
}

#download-icon {
font-size: 80px;
vertical-align: middle;
line-height: 120px;
}

#download-icon + span {
vertical-align: middle;
line-height: 1;
}

.container-border {
border-style: solid;
border-color: rgb(0, 143, 197);
padding: 5px;
min-height: 120px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="container-border">
<i class="material-icons" style="color:rgb(0,143,197);" id="download-icon">file_download</i>
<span class="download"> Download list of charities that have <b> not submitted </b> data yet </span>
</div>
</div>
</div>
</div>

预览

preview

关于html - 如何在盒子/容器中水平和垂直居中对齐文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47408805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com