Html h1 标签中的两行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6846448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:46:15  来源:igfitidea点击:

Two lines in h1 tag

htmlcss

提问by Oded Harth

I need to fit two lines in one h1 tag (instead of making two separated h1 tags).

我需要在一个 h1 标签中放入两行(而不是制作两个分开的 h1 标签)。

How can I create a line break inside of h1 tag?

如何在 h1 标签内创建换行符?

回答by Tom Walters

Using:

使用:

<h1>Line 1 <br/> Line 2</h1>

回答by JWorks Studios

A W3C validatedmethod is

W3C验证方法是

<h1>Line 1 <span style = "display: block;">Line 2</span></h1>

回答by zoul

You can insert markup inside h1, so that you can simply do <h1>foo<br>bar</h1>.

你可以在里面插入标记h1,这样你就可以简单地做<h1>foo<br>bar</h1>

回答by marcanuy

Summarizing all clever answers, this is what https://validator.w3.orgsays for each one:

总结所有聪明的答案,这就是https://validator.w3.org对每个答案所说的:

Validated:

验证:

<h1>Line 1 <br/> Line 2</h1>
<h1>Line 1<br>Line 2</h1>
<h1>Line 1 <span style = "display: block;">Line 2</span></h1>

Invalid

无效的

<h1>
    <p>Line1</p>
    <p>Line2</p>
</h1>

Reason:

原因:

Error: Element p not allowed as child of element h1 in this context

错误:在此上下文中不允许元素 p 作为元素 h1 的子元素



<h1>
  <div>line1</div>
  <div>line2</div>
</h1>

Reason:

原因:

Error: Element div not allowed as child of element h1 in this context.

错误:在此上下文中不允许元素 div 作为元素 h1 的子元素。



Tested code:

测试代码:

<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>Line 1 <br/> Line 2</h1>
<h1>Line 1<br>Line 2</h1>
<h1>
    <p>Line1</p>
    <p>Line2</p>
</h1>
<h1>Line 1 <span style = "display: block;">Line 2</span></h1>

<h1>
  <div>line1</div>
  <div>line2</div>
</h1>
</body>
</html>