[英]Aligning text in div vertically
我正在开发一个使用离子元素的应用程序。 我正在使用图标显示一些内容,并且遇到了问题。 这是我的代码:
HTML:
<ion-view view-title="TITLE" ng-popstate="onPopState($state)">
<ion-content class="background-change" scroll="true" has-bouncing="false">
<div class="this-dir">
<div class="dir-icon"><i ng-class="theIcon"></i></div>
<div class="dir-icon"><i ng-class="theIcon"></i></div>
<div class="dir-icon"><i ng-class="theIcon"></i></div>
<div class="dir-text"><strong>BLAHA</strong></div>
<div class="dir-icon"><i ng-class="theIcon"></i></div>
<div class="dir-icon"><i ng-class="theIcon"></i></div>
<div class="dir-icon"><i ng-class="theIcon"></i></div>
</div>
</ion-content>
</ion-view>
CSS:
.this-dir {
margin: 0px auto;
padding-top: 10px;
text-align: center;
background-color: #fff;
border-top: 1px solid #dedede;
}
.this-dir .dir-icon {
display: inline-block;
text-align: center;
padding: 0px 2px;
font-size: 20px;
}
.this-dir .dir-text {
display: inline-block;
text-align: center;
padding: 0px 3px;
}
角度控制器:
if (($scope.transaction.transaction[direction].destination_id) > ($scope.transaction.transaction[direction].origin_id)) {
$scope.theIcon = "ion-android-arrow-forward";
} else {
$scope.theIcon = "ion-android-arrow-back";
}
结果如下:
如您所见,文本当前在图标的底部对齐,但我希望文本在图标的中间对齐。 我试过使用vertical-align:middle;
使用table-cell
但这只会使所有文本和单元格向左移动。 我还尝试在内部div上使用margin-top
和padding-top
,但这只能同时移动所有箭头和文本。
在.dir-icon和.dir-text上添加vertical-align: middle
在.dir-text上添加等于.dir-icon的高度的行高。
工作小提琴: https : //jsfiddle.net/199n5d6t/ (为可见性在图标上添加了宽度,高度和背景颜色,您可以忽略此设置)
为<strong>
元素添加类,并使用以下CSS:
strong.ClassName {
vertical-align: super;
}
您必须将文本的行高设置为等于图标的高度,然后垂直对齐文本,如Leon所说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.