我<br/>后如何使一条线在中间对齐

时间:2019-02-22 12:05:15

标签: html css

例如-<h1>Welcome to the best blog website!<br/> New blog is out!<h1>

这样显示-

Welcome to the best blog website!

New blog is out!

我希望它显示为这样-

Welcome to the best blog website!

        New blog is out!

2 个答案:

答案 0 :(得分:3)

将元素设置为inline-block,然后将文本居中放置:

h1 {
  display: inline-block;
  text-align: center
}
<h1>Welcome to the best blog website!<br/> New blog is out!</h1>

如果要保持块级别的行为,可以添加一个额外的div:

h1 {
  display: inline-block;
  text-align: center
}
<div>
  <h1>Welcome to the best blog website!<br/> New blog is out!</h1>
</div>
<p>some text</p>

或使用display:table

h1 {
  display: table;
  text-align: center
}
<h1>Welcome to the best blog website!<br/> New blog is out!</h1>
<p>some text</p>

答案 1 :(得分:-2)

<blockquote>New blog is out!</blockquote>

如果您想要与代码相同的文本。然后添加这样的标签。

<pre> <blockquote>New blog is out!</blockquote></pre>