我希望 sometext 位于div边框之上。
.reg_form_fields_icon_box {
margin: 0 auto;
display: flex;
width: 80px;
height: 80px;
border: thin #dee5e7 solid;
}
.reg_form_fields_icon_box .reg_form_fields_icon {
margin: auto;
}
.reg_form_fields_icon_box .reg_form_fields_icon i {
font-size: 20px;
}
.reg_form_fields_icon_box .reg_form_fields_icon .text_name {
vertical-align: bottom;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="reg_form_fields_icon_box text-center">
<div class="reg_form_fields_icon">
<i class="glyphicon glyphicon-font"></i>
<div class="m-t-md text_name">
<span>sometext</span>
</div>
</div>
</div>
任何帮助都会很棒。
谢谢。
答案 0 :(得分:1)
您可以使用flexbox尝试以下解决方案:
.reg_form_fields_icon_box {
margin: 0 auto;
width: 80px;
height: 80px;
border: thin #dee5e7 solid;
}
.reg_form_fields_icon_box .reg_form_fields_icon {
display:flex;
flex-direction:column;
width:100%;
height:100%;
text-align:center;
justify-content:space-between;
}
.reg_form_fields_icon_box .reg_form_fields_icon i {
font-size: 20px;
top:calc(50% - 20px);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="reg_form_fields_icon_box text-center">
<div class="reg_form_fields_icon">
<i class="glyphicon glyphicon-font"></i>
<div class="m-t-md text_name">
<span>sometext</span>
</div>
</div>
</div>
答案 1 :(得分:0)
添加以下css:
div.reg_form_fields_icon_box {
position: relative;
}
div.reg_form_fields_icon_box div.reg_form_fields_icon div.text_name{
position: absolute;
bottom: 0;
}
答案 2 :(得分:0)
你可以自己flexbox
这样做,你不需要calc
来设置位置 - 位置绝对 - 所以这就是我所做的:< / p>
您可以使reg_form_fields_icon_box
成为flexbox
垂直且水平对齐。
重置margin: auto
并将其设置为100%height
和width
.reg_form_fields_icon_box .reg_form_fields_icon {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
position: relative;
margin: 0;
}
现在定位reg_form_fields_icon
绝对并使用以下内容将其与 bottom 对齐:
.reg_form_fields_icon_box .reg_form_fields_icon .text_name {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
见下面的演示:
.reg_form_fields_icon_box {
margin: 0 auto;
display: flex;
width: 80px;
height: 80px;
border: thin #dee5e7 solid;
}
.reg_form_fields_icon_box .reg_form_fields_icon {
margin: auto;
}
.reg_form_fields_icon_box .reg_form_fields_icon i {
font-size: 20px;
}
.reg_form_fields_icon_box .reg_form_fields_icon .text_name {
vertical-align: bottom;
}
/*ADDED THESE*/
.reg_form_fields_icon_box .reg_form_fields_icon {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
position: relative;
margin: 0;
}
.reg_form_fields_icon_box .reg_form_fields_icon .text_name {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="reg_form_fields_icon_box text-center">
<div class="reg_form_fields_icon">
<i class="glyphicon glyphicon-font"></i>
<div class="m-t-md text_name">
<span>sometext</span>
</div>
</div>
</div>
&#13;