html - 定位 Font Awesome 图标和一个段落

标签 html css twitter-bootstrap web position

我想将图标放置在句子的顶部,并且都在 Bootstrap 列中居中。我尝试更改段落和图标在 css 中的位置和显示,但它不起作用。 现在看起来像这样 enter image description here

我希望它是这样的 enter image description here

代码如下

#home-info {
    width: 500px;
    height: 200px;
    background-color: rgba(0,0,0,0.7);
    top: 550px;
    z-index: 1;
    position: absolute;
    
}

.col-md-3 {
    height: 100px;
    background-color: #1e2c38;
    text-align: center;
    color: white;
    border-bottom: 1px solid white;
    border-top: 1px solid white;
}

.col-md-4 {
    height: 300px;
    text-align: center;
    background-color: #1b2328;
}

.col-md-3 p {
    position: relative;
    width: 300px;
    text-align: center;
}
 <div class="container-fluid"> <!-- HOME INFO -->
                
                <div class="row">
                    <div class="col-md-3" id="navy2">
                        <div class="content-container">
                            <i class="fa fa-newspaper-o fa-3x" aria-hidden="true"></i>
                            <p>Learn more about our recent events and news!</p>
                        </div>
                    </div>
                    <div class="col-md-3" id="navy3">
                        <div class="content-container">
                            <i class="fa fa-calendar fa-3x" aria-hidden="true"></i>
                            <p>Stay up to date! Get the school's calendar here!</p>
                        </div>
                    </div>
                    <div class="col-md-3" id="navy2">
                        <div class="content-container">
                            <i class="fa fa-facebook-square fa-3x" aria-hidden="true"></i>
                            <p>Like and connect with us via Facebook!</p>
                        </div>
                    </div>
                    <div class="col-md-3" id="navy3">
                        <div class="content-container">
                            <i class="fa fa-youtube fa-3x" aria-hidden="true"></i>
                            <p>Learn more about us through our videos!</p>
                        </div>
                    </div>
                </div> <!-- ROW --> 

谢谢!

最佳答案

您可以通过将内部 p 设为 display:block 元素并使用 margin: 0 auto 使其居中...

.col-md-3 p {
    position: relative;
    width: 300px;
    display: block;
    margin: 0 auto;
}

http://www.codeply.com/go/kFJwok7k0T

但是,因为您在 .col-md-3 p 上设置了 300px,文本将在较小的宽度处被截断。最好不要在 .col-md-3 p 上设置任何特定宽度,这样它才能响应。

关于html - 定位 Font Awesome 图标和一个段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42616947/

相关文章:

html - 悬停时更改列表元素内的文本和链接颜色

javascript - 访问链接函数内的当前自定义指令元素

javascript - Spotify 网络播放 SDK

html - 为什么密码输入字段会自动填充?

css - jQuery UI - 使用不同的图标 css 和 .button()

javascript - 滚动表(但不是 thead)

html - 字体很棒和 ie7 问题

html - div 下方出现空白

css - 无法获取背景全宽

html - 当 Bootstrap 元素宽度被修改时,我如何在媒体查询中保持一致