Html H2和段落,内联?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4098124/
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
H2 and paragraph, inline?
提问by tlflow
I know paragraph and headings are block elements, so that's why I'm having a time wrapping my mind around what's the best way to do this accessibility-wise.
我知道段落和标题是块元素,所以这就是为什么我有时间思考什么是实现这种可访问性的最佳方法。
Let's say for instance I have copy like this:
例如,假设我有这样的副本:
*This is the heading.*This is the paragraph, blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.
*这是标题。*这是一段,等等等等等等等等等等等等等等啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
How would my HTML and CSS display this properly?
我的 HTML 和 CSS 将如何正确显示?
回答by Tomalak
h2, p {
display: inline;
}
div.p {
/* whatever margins/paddings you would normally apply to p */
}
and
和
<div class="p">
<h2>This is the heading.</h2>
<p>This is the paragraph</p>
</div>
You would need to enclose all <p>
in a block level element (like <div>
) to avoid that consecutive paragraphs collapse.
您需要将所有内容都包含<p>
在块级元素(如<div>
)中,以避免连续段落折叠。
回答by Harmen
You're almost answering the question yourself ;)
你几乎自己回答这个问题;)
h1, p {
display: inline;
}
Not sure if it works in IE6 though(I was confused with inline-block
here, inline
works fine in all browsers)
不确定它是否在 IE6 中工作(我对inline-block
这里感到困惑,inline
在所有浏览器中都可以正常工作)
回答by zzzzBov
alternatively:
或者:
h2
{
float: left;
/* adjust h2 font-size etc as needed */
}
...
<div>
<h2>heading</h2>
<p>Paragraph</p>
</div>
This has the advantage of still being able to specify margins, paddings, etc on the h2.
这具有仍然能够在 h2 上指定边距、填充等的优点。