我的目标是使标题与<p>
标签内的文本内联...所有这些都margin
与容器的填充物有关
我有以下html代码
<div id='homeContent'>
<!-- other headings and content here -->
<p><h3>Heading</h3> some text</br> more text</p>
<!-- other headings and content here -->
</div>
使用以下CSS
#homeContent h3, #homeContent h4, #homeContent p {
z-index: 0;
margin: 0px 16px;
padding-top: 8px;
}
#homeContent h3, #homeContent h4 {
display: inline;
}
#homeContent {
padding: 0px 16px;
margin: 32px 0px;
}
这就是我要发生的事情(考虑将代码块作为容器的边界)
H3 HEADING some text
more text here
这是我实际上得到的
H3 HEADING some text
more text here <-- notice here the text does not respect the margin given to the <p> tag
现在,如果我从段落标记中删除标题标记,则段落文本的行为正确,但显然不会与标题内联,这就是目标。
首先,标记中不能包含任何块级元素<p>
。即使您的代码具有:
<p><h3>Heading</h3> some text</br> more text</p>
它在浏览器中呈现如下:
因此,最好使用正确的代码,例如:
<h3>Heading</h3>
<p> some text</br> more text</p>
并使用CSS设置样式。
段落和标题是两种不同的动物。根据您在评论中的需要,我建议使用此标记:
h3 {color: red;}
h3 span {font-weight: normal; font-size: 0.8em;}
<h3>Heading <span>some text</br> more text</span></h3>
并进一步您的意见,我可以找到你想要让你<h3>
和<p>
在线运行的内容。我建议保留上面的标记并使用以下CSS:
h3, h3 + p {display: inline-block; /* Or inline */}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句