html - 居中响应文本

标签 html css responsive-design centering

我这里有一个 jsfiddle - http://jsfiddle.net/kw83kLmo/

这只是我需要在窗口中居中的一段文本。

文本需要设置宽度,因为我不希望它是容器的全宽。

当窗口变小时,文本需要保持在中心但会变窄。

在此处的示例中,它保持居中并响应,直到达到 600px,然后才保持该宽度。

我知道我已经设置了那个宽度,但我这样做是为了让它居中

<div class="container-fluid ">

    <div class="hero">

        <div class="hero_heading text-center">
            <h1>This is a heading This is a heading This is a heading </h1>
        </div>

    </div>

</div>

最佳答案

更新您的 h1 样式,如下所示。

.hero_heading h1 {
    border: 1px solid red;
    color: white;
    position: absolute;
    left: 0;
    right: 0;
    margin: 0 auto;
    max-width: 600px;
}

DEMO

关于html - 居中响应文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25446806/

相关文章:

jquery - rollOver 上的 CSS 叠加

css - 如何在 vue.js 应用程序中使用 CSS?

css - 具有响应值的表逻辑 bootstrap/html

css - 背景封面不适用于移动设备

javascript - 无法获取框架内容,未捕获 DOMException : Blocked a frame with origin "null" from accessing a cross-origin frame

javascript - 悬停时更改背景图像并保持事件状态

javascript - 如何确定鼠标指针是否位于应触发 MouseOver 的元素上?

html - 为 css Sprite (图像)菜单设置事件类

javascript - 我如何解释 setTimeout 的这种行为?

javascript - 以编程方式更改选中的复选框