html - 如何在 bootstrap 中将文本居中?

标签 html css twitter-bootstrap

<分区>

我有一个纯 html 代码:

    section.cta, section.cta2, section.cta3, section.cta4 {
      position: relative;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      background-size: cover;
      -o-background-size: cover;
      background-position: center;
      padding: 250px 0;
    }
    section.cta .cta-content, section.cta2 .cta2-content, section.cta3 .cta3-content,  section.cta4 .cta4-content {
      position: relative;
      z-index: 1;
    }
    section.cta .cta-content h2, section.cta2 .cta2-content h2, section.cta3 .cta3-content h2, section.cta4 .cta4-content h2 {
      margin-top: 0;
      margin-bottom: 25px;
      color: black;
      max-width: 450px;
      font-size: 50px;
    }
    
    section.cta .cta-content p  {
      color: black;
      max-width: 450px;
      font-size: 20px;
    }
    
    section.cta {
      background-image: url('https://cdn1.tnwcdn.com/files/2011/08/bliss.jpg');
    }
    
    @media (min-width: 768px) {
      section.cta .cta-content h2, section.cta2 .cta2-content h2, section.cta3 .cta3-content h2, section.cta4 .cta4-content h2 {
        font-size: 80px;
      }
    }
    section.cta .overlay {
      height: 100%;
      width: 100%;
      background-color: rgba(0, 0, 0, 0.5);
      position: absolute;
      top: 0;
      left: 0;
    }
<section class="cta">
        <div class="cta-content">
            <div class="container">
                <h2>this is header</h2>
                <p>this is some other text.</p>
            </div>
        </div>
        <div class="overlay"></div>
    </section>

结果是一个具有漂亮背景和左对齐文本的页面。

文本基本上是这样的:

|   this is header                                   |
|   this is some other text.                         |

当用户全屏查看网页时,它位于背景的最左侧。我想更改它,以便文本像这样可见:

|                  this is header                    |
|              this is some other text               |

我该怎么做?

我的 jsfiddle 在这里:

https://jsfiddle.net/0zfktus3/

最佳答案

h2p 中删除 max-width

在容器中添加一个类text-center

关于html - 如何在 bootstrap 中将文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42908487/

相关文章:

javascript - 从顶部滚动 x 像素后触发函数

javascript - 使用 nodejs 发送对 html 的响应来使用 REST

javascript - 自动完成菜单上方的输入框 - Bootstrap 3

javascript - (阅读更多链接)到模态淡入淡出 View

javascript - 如何在html中修复表格滚动中的标题

javascript - 查找已提交表单的所有提交按钮

javascript - img 高度与 img 宽度成比例,但 img 宽度占父级的百分比

css - 改变几何图标的颜色

html - 我怎样才能使这个 css webkit 从左到右过渡?

javascript - 4.0.0 BETA 中的 Bootstrap 下拉菜单