简体   繁体   English

将字体很棒的图标对齐到中心

[英]Aligning font-awesome icons to center

 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <section> <div class="container"> <div class="row"> <div class="col-md-4"> <i class="fa fa-book fa-3x text-center" aria-hidden="true"></i> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> <div class="col-md-4"> <i class="fa fa-book fa-3x" aria-hidden="true"></i> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> <div class="col-md-4"> <i class="fa fa-book fa-3x" aria-hidden="true"></i> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> </div><!--end row--> </div><!--end container--> </section> 

This is my code. 这是我的代码。 I intend to center the font awesome icons to the center in their respective columns but I'm unable to do it. 我打算将字体真棒图标集中在各自列的中心,但我无法做到。

  1. You can move text-center to your column <div> , then all the text in this <div> will be centered (the first row in my example). 您可以将text-center移动到列<div> ,然后此<div>所有文本都将居中(我的示例中的第一行)。
  2. You can add extra <div> with class text-center and move your icon inside it (the second row in my example). 您可以使用类text-center添加额外的<div>并在其中移动您的图标(我的示例中的第二行)。

 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <section> <div class="container"> <div class="row"> <div class="col-md-4 text-center"> <i class="fa fa-book fa-3x" aria-hidden="true"></i> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> <div class="col-md-4"> <div class="text-center"> <i class="fa fa-book fa-3x" aria-hidden="true"></i> </div> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> </div><!--end row--> </div><!--end container--> </section> 

JSFiddle 的jsfiddle

I think that this will work: 我认为这会奏效:

<div class="col-md-4" style="text-align:center;">
      <i class="fa fa-book fa-3x text-center" aria-hidden="true"></i>         
      <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p>
</div>
.center{
text-align:center;
width:50%;
}

HTML HTML

<div class="center"><i class="fa fa-book fa-3x text-center" aria-hidden="true"></i></div>

This brings it to the middle as the way u wanted. 这就像你想要的那样把它带到中间。

  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <section> <div class="container"> <div class="row"> <div class="col-md-4"> <div class="text-center"><i class="fa fa-book fa-3x" aria-hidden="true"></i></div> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> <div class="col-md-4"> <div class="text-center"><i class="fa fa-book fa-3x" aria-hidden="true"></i></div> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> <div class="col-md-4"> <div class="text-center"><i class="fa fa-book fa-3x" aria-hidden="true"></i></div> <p>Ne mundi fabulas corrumpit vim, nulla vivendum conceptam</p> </div> </div><!--end row--> </div><!--end container--> </section> 

Put the font awesome icon into a separate div and apply "text-center" class. 将字体真棒图标放入单独的div并应用“text-center”类。 It will align font-awesome icons to center. 它将字体 - 令人敬畏的图标对齐到中心。

使用这种最简单的方法:

<div class="text-center"><i class="fa fa-book fa-3x text-center" aria-hidden="true"></i></div>

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

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