html - 垂直居中带有字形的文本

标签 html css glyphicons

我正在尝试VERTICALLY 将带有字形的文本居中...我似乎无法弄清楚如何做到这一点。我知道它将使用内联样式或 CSS,但我似乎无法获得正确的语法。

代码:

<div class="col-lg-3">
    <div class="menu-item blue">
        <div class="panel-heading text-center">
            <a href="#feature-modal" data-toggle="modal">
                <i class="fa fa-magic"></i>
                <p>Test</p>
            </a>
        </div>
        <hr />
        <div class="panel-body"> 
            <p><i class="glyphicon glyphicon-credit-card"></i><a href="http://www.google.com">Test Tab</a></p>
        </div>
    </div>
</div>

CSS:

   <style type="text/css">
    @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,700,600);
    @import url(http://fonts.googleapis.com/css?family=Oswald:400,300);

    a,
    a:hover,
    a:focus,
    a:active,
    a.active {
        outline: 0;
    }

    ul, ol {
        margin: 0;
        padding: 0;
    }

    li {
        list-style: none;
    }

    a {
        color: #FF432E;
        text-decoration: none;
    }

        a:hover {
            text-decoration: none;
        }

    p {
        font-family: 'Open Sans', sans-serif;
        font-size: 13px;
        line-height: 21px;
    }

    /**** Start Section Title Section ****/

    .section-title h3 {
        color: #666 !important;
        font-size: 28px;
        font-family: 'Oswald', sans-serif;
        text-transform: none;
    }

    .section-title p {
        padding-bottom: 60px;
        color: #999;
        font-size: 18px;
        //font-style: italic;
        font-weight: 300;
    }

    /**** Start Background Color ****/

    .blue {
        background: #28ABE3;
    }

    .green {
        background: #72bf48;
    }

    .red {
        background: #FF432E;
    }

    .light-red {
        background: #FB6648;
    }

    .light-orange {
        background: #FA6900;
    }

    .color {
        background: #0ECEAB;
    }

    .purple {
        background: #9b59b6;
    }


    /**** Start Main Body Section ****/

    .mainbody-section {
        padding-top: 30px;
        padding-bottom: 30px;
    }

    .menu-item {
        color: #fff;
        /*padding-top: 45px;
        padding-bottom: 45px;
        margin-bottom: 30px;*/
        -webkit-transition: all 0.3s;
        transition: all 0.3s;
        border: 5px solid transparent;
    }

        .menu-item:hover {
            border: 5px solid rgba(255, 255, 255, 0.70);
        }

        .menu-item a {
            color: #fff;
            font-size: 15px;
            /*display: block;*/
            -webkit-transition: all 0.3s;
            transition: all 0.3s;
        }
/**/
            .menu-item a p {
                font-family: 'Oswald', sans-serif;
                font-weight: 300;
                font-size: 20px;
            }

            .menu-item a i {
                font-size: 50px;
                padding-bottom: 20px;
            }

        .menu-item:hover a {
            text-decoration: none;
        }

    @media only screen and (min-width : 600px) and (max-width : 991px) {

        .menu-item {
            display: inline-block;
            width: 32.8%;
        }

            .menu-item.responsive {
                width: 49.5%;
                float: left;
                margin-right: 3px;
                margin-top: 5px;
            }

            .menu-item.responsive-2 {
                width: 49.5%;
                float: right;
                margin-top: 5px;
            }
    }



    @media only screen and (min-width : 992px) and (max-width : 1199px) {

        .menu-item {
            padding-top: 15px;
            padding-bottom: 15px;
        }

            .menu-item a i {
                font-size: 32px;
            }

            .menu-item a p {
                font-size: 16px;
            }
    }

    /*Glyphicon styling*/
    .glyphicon-credit-card:before {
        margin-right: 20px;
        font-size: 30px;
    }

    .panel-body i + a { 
        vertical-align: text-bottom;
    }
</style>

最佳答案

您需要使用 vertical-align: text-bottom因为它将 anchor 元素文本与 p 元素字体的底部对齐。

.panel-body i + a { /* Select links after font icons */
  vertical-align: text-bottom;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet" />
<div class="col-lg-3">
  <div class="menu-item blue">
    <div class="panel-heading text-center">
      <a href="#feature-modal" data-toggle="modal">
        <i class="fa fa-magic"></i>
        <p>Test</p>
      </a>
    </div>
    <hr />
    <div class="panel-body">
      <p><i class="glyphicon glyphicon-credit-card"></i><a href="http://www.google.com">Test Tab</a>
      </p>
    </div>
  </div>
</div>

关于html - 垂直居中带有字形的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32742889/

相关文章:

html - 如何删除所选选项卡的底部边框

javascript - JQuery 将两个图像设置为与另一个图像相同的位置

css - 在不改变列位置的情况下固定 Bootstrap 列

asp.net-mvc - 带有字形图标和不同字体文本的 ASP.NET Actionlink

Java,从 DOM 获取带标签的文本内容,按照浏览器显示的顺序

javascript - 如何使用javascript在父div内显示子div而不触发其他div

javascript - 使用javascript查找元素在html页面中的位置

javascript - 根据从 MSSQL 数据库检索的数值在 div 中动态创建星形字形 C#

css - Bootstrap 3 无法正确显示字形

javascript - 不使用时滚动条会淡出。这不应该发生