html - 居中 Font Awesome 图标

标签 html css font-awesome

以前有人问过这个问题,但在阅读了这些线程中的每条评论后,我无法得到有效的解决方案。

我试图简单地将 Font Awesome 图标与 div 中的文本居中。文本完美居中,图标偏左。

HTML:

<div class="work-section" id="work">
    <div class="container">
        <div class="work-section-head text-center wow fadeInRight" data-wow-delay="0.4s">
            <h3>Event name placeholder</h3>         
        </div>
        <div class="work-section-grids text-center wow fadeInUp" data-wow-delay="0.4s">
            <div class="col-md-3 work-section-grid text-center">
                <i class="fa fa-users fa-5x icons"></i>
                <h4>Who</h4>
                <p>People placeholder</p>               
            </div>
            <div class="col-md-3 work-section-grid wow fadeInUp" data-wow-delay="0.6s">
                <i class="fa fa-calendar fa-5x icons"></i>
                <h4>When</h4>
                <p>Date placeholder </p>                
            </div>
            <div class="col-md-3 work-section-grid wow fadeInUp" data-wow-delay="0.8s">
                <i class="fa fa-globe fa-5x icons"></i>
                <h4>Where</h4>
                <p>Place placeholder</p>
            </div>
            <div class="col-md-3 work-section-grid wow fadeInUp" data-wow-delay="1s">
                <i class="fa fa-question-circle fa-5x icons"></i>
                <h4>What</h4>
                <p>Information placeholder </p>
            </div>
        </div>  
    </div>
</div>

CSS:

body,
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: "Lato","Helvetica Neue",Helvetica,Arial,sans-serif;
    font-weight: 600;
}

h1 {
    font-size: 80px;
    font-weight: bold;
    color: #fff;
    margin: 100px 0 30px 0;
}


p {
  font-size: 20px;
  line-height:30px;
}
a {
  color:#c0392b;
}
a:hover {
  color: #f96e5e;
}
a img {
  border:0;
}
a.button {
  display:inline-block;
  color:#FFF;
  background-color:#c0392b;
  text-decoration:none;
  padding:10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
  margin-bottom:10px;
  -webkit-transition: background 0.2s ease-out;
  -moz-transition: background 0.2s ease-out;
  -ms-transition: background 0.2s ease-out;
  -o-transition: background 0.2s ease-out;
  transition: background 0.2s ease-out;
}
a.button:hover {
  background-color:#f96e5e;
}
a.button.small {
  background-color:#7f8c8d;
  padding:8px;
  font-size:0.8em;
}
a.button.small:hover {
  background-color:#95a5a6;
}
.section {
  margin:0;
  padding:40px;
  background-color:#ecf0f1;
}
.section.odd {
  background-color:#dbe0e0;
}
.wrapper {
  margin:40px auto;
  width:1200px;
}
.half {
  width:49%;
  display:inline-block;
  vertical-align:middle;
}
.padding {
  20px;
}
.half.left .padding {
  padding:0 20px 20px 0;
}
.half.right .padding {
  padding:0 0 20px 20px;
}
.half img {
  max-width:100%;
  width: auto !important;
  height:auto !important;
}
.space {
  height:40px;
}


/* section-specific styles */
#header {
  background-color:#c0392b;
  background-repeat:repeat-x;
  background-position:bottom center;
  color:#FFF;
  padding-bottom:90px;
}
#header h1, #header h2 {
  text-align:center; 
}
#header h2 {
  color: #FDD;
  margin: 20px 0 20px 0;
}

#footer {
  background-color: #152330;
  background-repeat:repeat-x;
  background-position: top center;
  color:#FFF;
}



.lead {
    font-size: 18px;
    font-weight: 400;
}

.divider{
    width:5px;
    height:auto;
    display:inline-block;
}


.intro-header {
    padding-top: 50px; 
    padding-bottom: 25px;
    height: 60%;
    text-align: center;
    color: #f8f8f8;
    background: url(../img/CarBanner_contrast.jpg) no-repeat bottom center;
    background-size: cover;

}

.intro-message {
    position: relative;
    padding-top: 20%;
    padding-bottom: 20%;
}

.intro-message > h1 {
    margin: 0;
    text-shadow: 2px 2px 3px rgba(0,0,0,0.6);
    font-size: 4em;
}

.intro-divider {
    width: 400px;
    border-top: 1px solid #f8f8f8;
    border-bottom: 1px solid rgba(0,0,0,0.2);
}

.intro-message > h3 {
    text-shadow: 2px 2px 3px rgba(0,0,0,0.6);
    font-size: 1.9em;
}

@media(max-width:767px) {
    .intro-message {
        padding-bottom: 15%;
    }

    .intro-message > h1 {
        font-size: 3em;
    }

    ul.intro-social-buttons > li {
        display: block;
        margin-bottom: 20px;
        padding: 0;
    }

    ul.intro-social-buttons > li:last-child {
        margin-bottom: 0;
    }

    .intro-divider {
        width: 100%;
    }
}

.network-name {
    text-transform: uppercase;
    font-size: 18px;
    font-weight: 400;
    letter-spacing: 2px;
}

.content-section-a {
    padding: 50px 0;
    background-color: #f8f8f8;
}

.content-section-b {
    padding: 50px 0;
    border-top: 1px solid #e7e7e7;
    border-bottom: 1px solid #e7e7e7;
}

.section-heading {
    margin-bottom: 30px;
}

.section-heading-spacer {
    float: left;
    width: 200px;
    border-top: 3px solid #e7e7e7;
}

.banner {
    padding: 100px 0;
    color: #f8f8f8;
    background: url(../img/banner-bg.jpg) no-repeat center center;
    background-size: cover;
}

.banner h2 {
    margin: 0;
    text-shadow: 2px 2px 3px rgba(0,0,0,0.6);
    font-size: 3em;
}

.banner ul {
    margin-bottom: 0;
}

.banner-social-buttons {
    float: right;
    margin-top: 0;
}

@media(max-width:1199px) {
    ul.banner-social-buttons {
        float: left;
        margin-top: 15px;
    }
}

@media(max-width:767px) {
    .banner h2 {
        margin: 0;
        text-shadow: 2px 2px 3px rgba(0,0,0,0.6);
        font-size: 3em;
    }

    ul.banner-social-buttons > li {
        display: block;
        margin-bottom: 20px;
        padding: 0;
    }

    ul.banner-social-buttons > li:last-child {
        margin-bottom: 0;
    }
}

footer {
    padding: 50px 0;
    background-color: #f8f8f8;
}

.styled-button-1{
  display: inline-block;  
  *display: inline;
  zoom: 1;
  padding: 6px 20px;
  margin: 0;
  cursor: pointer;
  border: 1px solid #bbb;
  overflow: visible;
  font-size:16.5px;
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 1px;  
  font-family: 'Helvetica Neue', sans-serif;
  text-decoration: none;
  white-space: nowrap;
  color: #fff;
  background-color: #ddd;
  background-image: linear-gradient(top, rgba(255,255,255,1),
                                         rgba(255,255,255,0)),
                    url(data:image/png;base64,iVBORw0KGg[...]QmCC); 
  transition: background-color .2s ease-out;
  background-clip: padding-box; /* Fix bleeding */
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .3),
              0 2px 2px -1px rgba(0, 0, 0, .5),
              0 1px 0 rgba(255, 255, 255, .3) inset;
  text-shadow: 0 .4px 0 rgba(255,255,255, .9);  
}





.work-section {
    padding: 3em 0;
}
.work-section-head h3 {
    color: #394b50;
    font-size: 2.2em;
    font-weight: 900;
    text-transform: uppercase;
}
.work-section-head p {
    color: #394b50;
    font-size: 1.2em;
    font-weight: 500;
}
.work-section-grid {
    margin-top:8em;
    position:relative;
}
span.arrow1 {
    position: absolute;
    top: -10px;
    right: 150px
}

.work-section-grid h4 {
    color:#394b50;
    font-family: 'Lato', sans-serif;
    font-size:1.5em;
    font-weight:700;
    margin-bottom:0.8em;
    text-transform: uppercase;
    margin-top:4em;
}
.work-section-grid p {
    color: #7b7b7b;
    font-size: 0.95em;
    font-weight: 400;
    line-height: 1.8em;
    margin-bottom:6em;
}
a.work {
    color: #fff;
    font-family: 'Lato', sans-serif;
    font-size: 1em;
    text-decoration: none;
    background: #ffbb42;
    text-transform: uppercase;
    font-weight: 400;
    padding: 11px 23px;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -o-border-radius: 4px;
    -ms-border-radius: 4px;
}
a.work:hover {
    background:#394b50;
}

@media screen and (max-width: 800px){
    span.menu{
        width:28px;
        height:28px;
        background:url(../images/nav.png)no-repeat;
        display: inline-block;
        float:right;
        cursor: pointer;
        margin-top: 10px;
    }
    .top-menu{
        width:100%;
        display: none;
        text-align:center;
        background:#fff;
        padding:0;
    }
    .top-menu ul{
        float:none;
        width:100%;
    }
    .top-menu ul li{
        display:block;
        float: none;
    }
    .top-menu ul li a{
        display: block;
        padding: 10px 0px;
    }
    .top-menu ul li a.active {
        padding: 10px 13px;
    }
    .top-menu ul li a:hover {
        padding: 10px 13px;
    }
    .header {
        padding: 1.2em 0;
    }
    .about_left {
        width:50%;
        float:left;
    }
    .about_right {
        width:50%;
        float:right;
    }

    .work-section {
        padding: 4em 0;
    }

    .work-section-grid {
        margin-top: 6em;
        width: 25%;
        float: left;
        padding: 10px;
    }
    .work-section-grid h4 {
        font-size: 1.3em;
        margin-bottom: 0.6em;
        margin-top: 3.8em;
    }
    .work-section-grid p {
        font-size: 0.9em;
    }
}

[class^="icons"], [class*=" icons"] {
    text-align:center;
    display:inline-block;
}

当我设置图标 width:7% 时,我可以让它居中,但这只是一个静态解决方案。

JSFILE:http://jsfiddle.net/5d4z0x8h/

最佳答案

只需一个 text-align:center; 就可以了

.wow{
    border:1px solid black;
    text-align:center;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-md-3 work-section-grid wow fadeInUp" data-wow-delay="0.6s">
                <i class="fa fa-calendar fa-5x icons"></i>
                <h4>When</h4>
                <p>Date placeholder </p>                
            </div>

关于html - 居中 Font Awesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29313885/

相关文章:

javascript - 如何根据具有动态宽度的父容器设置比例宽度

javascript - 将图像裁剪到所需的长宽比,然后调整大小

php - 改变列宽 Yii

javascript - 如何做最合适的垂直对齐

font-awesome - 中文符号代替功能或 ionic 图标

css - 减少旧浏览器对 FontAwesome 的支持

PHP 下拉排序

javascript - 单击任意位置以关闭侧边导航栏 javascript

html - 仅在父级而不是子级上应用列表样式类型

css - 自定义复选框在 Firefox 上不起作用