将< p>在中心< h1> [英] placing a <p> beside a centered <h1>

查看:98
本文介绍了将< p>在中心< h1>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是代码里面的所有内容。但现在我只想将标题居中并通过不将标题移动到左侧来追加日期。标题必须保留在中间,附加日期。

 < div class =row center> 
< div class =col-md-12>
< h1 style =display:inline;>标题< / h1>< p style =display:inline;> 2014年6月27日< / p>
< / div>
< / div>


解决方案

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

 < div class =row text-center> 
< div class =col-md-12>
< h1 class =title>标题< / h1>
< p> 2014年6月27日< / 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; / *根据行高调整margin-top * /
}



演示:< a href =http://plnkr.co/edit/tFOrJUP4g8Pr0LxLWN9w?p=preview =nofollow> http://plnkr.co/edit/tFOrJUP4g8Pr0LxLWN9w?p=preview



由于 col-md-12 position:relative code> p 绝对值,并修复垂直对齐与负边距(调整您的线高度)。

而不是 .center 类,您可以使用Bootstrap .text-center class中的build。


below is the code where it center everything inside. But now I just want to center the Title and append the date by not moving the Title to the left. The title have to remain in the middle with date appended behind. How can I achieve that?

<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>

解决方案

Here is a trick, you can try:

<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 */
}

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

Since col-md-12 has position: relative you can position p absolutely, and fix vertical alignment with negative margin (adjust for your line height).

Also instead of .center class you can use build in Bootstrap .text-center class.

这篇关于将&lt; p&gt;在中心&lt; h1&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆