twitter-bootstrap 将字体真棒图标对齐到中心

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42315431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 00:37:01  来源:igfitidea点击:

Aligning font-awesome icons to center

csshtmltwitter-bootstraptwitter-bootstrap-3

提问by Rohan Mayya

<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.

这是我的代码。我打算将字体真棒图标居中到各自列的中心,但我无法做到。

回答by sergdenisov

  1. You can move text-centerto your column <div>, then all the text in this <div>will be centered (the first row in my example).
  2. You can add extra <div>with class text-centerand move your icon inside it (the second row in my example).
  1. 您可以移动text-center到您的 column <div>,然后其中的所有文本<div>都将居中(我的示例中的第一行)。
  2. 您可以添加额外<div>的类text-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 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

回答by Bijal Patel

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>

回答by Venky

.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.

这将它按照您想要的方式带到中间。

回答by Subash Matheswaran

    <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. It will align font-awesome icons to center.

将字体真棒图标放入单独的 div 并应用“文本中心”类。它将字体很棒的图标对齐到中心。

回答by Piyali

Use this simplest way:

使用这个最简单的方法:

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