简体   繁体   English

Bootstrap 3将文本垂直对齐到ionicon

[英]Bootstrap 3 vertical align text to ionicon

I am trying to align an ionicon icon and text to its side in a vertical way inside a button using Bootstrap 3. 我正在尝试使用Bootstrap 3在按钮内以垂直方式将ionicon图标和文本对齐其侧面。

I want the text to be vertically aligned to the center of the button with the icon also vertically aligned. 我希望文本垂直对齐按钮的中心,图标也垂直对齐。

The default seems to align the icon and the text using their lowest points. 默认似乎使用最低点对齐图标和文本。

My HTML is: 我的HTML是:

<div class="col-xs-4 text-right">
   <a href="/signout" class="btn btn-xs btn-danger sign-out">
      <i class="ion-power ion-fw"></i>
      <span class="menu-label">Sign Out</span>
   </a>
</div>

My CSS is: 我的CSS是:

.main-header .navbar .dropdown-menu li a.sign-out {
   color: #fff !important;
   vertical-align: middle;
}

.ion-fw {
    width: 1.28571429em;
    text-align: center;
}

My CSS targets the pair OK as their colors are correct. 我的CSS将对确定为OK,因为它们的颜色正确。 I have tried padding and margins on .menu-label but that moves the text and icon. 我已经尝试过.menu-label填充和边距,但这会移动文本和图标。

How do I adjust the text to the middle of the icon's height? 如何将文本调整到图标高度的中间? Thanks! 谢谢!

Example: 例: 在此处输入图片说明

Change this 改变这个

 .ion-fw {
    width: 1.28571429em;
    text-align: center;
}

to this 对此

.ion-fw {
    width: 1.28571429em;
    text-align: center;
   vertical-align: middle;
}

vertical-align works on elements in the same container and so must be applied to the contents...not the parent element. vertical-align适用于同一容器中的元素,因此必须应用于内容...而不是父元素。

 .ion-fw { width: 1.28571429em; text-align: center; vertical-align: middle; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" /> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="col-xs-4 text-right"> <a href="/signout" class="btn btn-xs btn-danger sign-out"> <i class="ion-power ion-fw"></i> <span class="menu-label">Sign Out</span> </a> </div> 

This works for me: 这对我有用:

 .ion-fw { display: inline-block; vertical-align: bottom; height: 1.4em; font-size: 1.1em; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" /> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="col-xs-4 text-right"> <a href="/signout" class="btn btn-xs btn-danger sign-out"> <i class="ion-power ion-fw"></i> <span class="menu-label">Sign Out</span> </a> </div> 

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

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