2010-11-04 73 views
4

我知道段落和标题是块元素,所以这就是为什么我有一个包裹时我的脑海里围绕什么是做到这一点的无障碍明智的最佳途径。H2和段落,内联?

比方说,比如我有复制这样的:

* 这是标题。 *这是一段,等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等。

如何将我的HTML和CSS显示这正常吗?

回答

8
h2, p { 
    display: inline; 
} 
div.p { 
    /* whatever margins/paddings you would normally apply to p */ 
} 

<div class="p"> 
<h2>This is the heading.</h2> 
<p>This is the paragraph</p> 
</div> 

,您将需要附上所有<p>在块级元素(如<div>),以避免连续的段落崩溃。

+0

我责怪它是在早晨太早,我睡觉太晚了。谢谢您的帮助。 – tlflow 2010-11-04 15:27:03

6

您几乎回答自己的问题;)

h1, p { 
    display: inline; 
} 

不知道它在IE6的作品虽然 (我是用inline-block这里混淆,inline在所有浏览器正常工作)

1

或者:

h2 
{ 
    float: left; 
    /* adjust h2 font-size etc as needed */ 
} 
... 
<div> 
<h2>heading</h2> 
<p>Paragraph</p> 
</div> 

这有仍然能够在H2指定页边距,填充等的优势。