将< p>在中心< h1> [英] placing a <p> beside a centered <h1>
本文介绍了将< 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.
这篇关于将< p>在中心< h1>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文