html - 在居中的 <h1> 旁边放置一个 <p>

标签 html css twitter-bootstrap

下面是将所有内容置于中心的代码。但现在我只想将标题居中并通过不将标题向左移动来附加日期。标题必须保留在中间,日期附加在后面。我怎样才能做到这一点?

<div class="row center">
    <div class="col-md-12">
        <h1 style="display:inline;">Title</h1><p style="display:inline;"> 27th June 2014</p>
    </div>
</div>

最佳答案

这里有一个技巧,你可以试试:

<div class="row text-center">
    <div class="col-md-12">
        <h1 class="title">Title</h1>
        <p>27th June 2014</p>
    </div>
</div>

CSS:

.text-center .title {
    display: inline-block;
}
.text-center .title + p {
    position: absolute;
    display: inline-block;
    top: 50%;
    margin: -5px 0 0 10px; /* adjust margin-top based on your line height */
}

演示:http://plnkr.co/edit/tFOrJUP4g8Pr0LxLWN9w?p=preview

因为 col-md-12position: relative 你可以绝对定位 p ,并用负边距修复垂直对齐(调整你的行高)。

此外,您还可以在 Bootstrap .text-center 类中使用构建类,而不是 .center 类。

关于html - 在居中的 <h1> 旁边放置一个 <p>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24446559/

相关文章:

javascript - Bootstrap Datepicker - 从内联/嵌入式版本中选择日期

html - 我怎样才能使图标始终位于选择输入的右侧?

javascript - 悬停动画时更改属性

javascript - 如何使两个 tbody 元素之间的分隔线可移动

javascript - 不使用 Jquery 查找最后一个 td

css - Bootstrap 定制 : Why should I use LESS?

jquery - 尝试在 2 种不同的屏幕尺寸下切换此 jQuery 菜单

javascript - 在 JavaScript 中选择按钮之前禁用加载功能?

html - 奇怪的边框在视频标签上留下黑色

html - 百分比 CSS 不准确