twitter-bootstrap - 将 anchor 标签内的内容居中对齐

标签 twitter-bootstrap css font-awesome

我需要帮助以使 anchor 内的内容垂直对齐。我正在使用 Font Awesome 图标和 anchor 标记内的文本。我希望图标和文本在中心垂直和水平对齐。我能够进行水平对齐,但不能进行垂直对齐。不知道我错过了什么

.my-tile {
    height: 90px;
    margin-left: 0.5%;
    margin-right: 0.5%;
    float: left;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    /*display: table;*/
    border-radius: 3px;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;    
    position: relative;    
    align-items: center;
    background: linear-gradient(#af4b17, #e57234); /* Standard syntax */
    background: -moz-linear-gradient(#af4b17, #e57234 35%, #e57234);
    background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #af4b17),color-stop(.35, #e57234),color-stop(1, #e57234));
    border: 1px solid #af4b17;
    text-align: center;
    justify-content: center;
    vertical-align:middle;
}

    .my-tile > a {
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        /*padding-bottom: 10px;*/
        text-decoration: none;
        position: relative;           
        vertical-align:middle;        
    }

        .my-tile > a .link-icon {
            color: white !important;
            font-size: 30px !important;            
            height: 1em;
            margin: 0 auto 5px;            
            width: 1em;            
            display: block;
            
        }        

.my-tile-half {
    width: 49%;
}
<script src="https://use.fontawesome.com/releases/v5.0.9/js/all.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js"></script>
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
	<div class="row">
            <div class="col-md-4">
                <div class="row">
                    <div class="col-md-12">                        
                        <div class="my-tile my-tile-half">
                            <a href="#">
                                <div>
                                    <span class="fas fa-upload link-icon"></span>Upload
                                </div>
                            </a>
                        </div>
                        <div class="my-tile my-tile-half">
                            <a href="#">
                                <div>
                                    <span class="fas fa-clipboard-check link-icon"></span>Done
                                </div>
                            </a>
                        </div>
                    </div>
                </div>                
            </div>
        </div>

最佳答案

对齐内部所有内容的最佳方法<a></a>是使用灵活

a {
    display: flex;
    align-items: center;
    justify-content: center;

    /** Use this rule if the tag has a parent with specific height */ 
    height: 100%; 
}
查看此演示:https://jsfiddle.net/gkL5of1z/3/

关于twitter-bootstrap - 将 anchor 标签内的内容居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49697943/

相关文章:

html - 如何使用 CSS 增加 unicode 图标相对于其容器的 Font Awesome 的大小

fonts - 如何在字体中使用 browserify

html - 按钮的文本在 Bootstrap 中失去锐化并略微模糊

twitter-bootstrap - 如何制作对 Angular 线div

python - 短划线范围 slider ,两侧都有输入

javascript - 在 Android 浏览器上,在文本框内输入时整个页面会上下跳动?

html - 为什么HTML代码环绕

javascript - 向 FontAwesome 图标添加事件监听器

javascript - Bootstrap 3 导航栏折叠

jquery - 将 foreach 与 Bootstrap 的网格一起使用以列出元素