HTML/CSS 显示:内嵌问题
我的 HTML 文档中有多个文本段落。此外,在不同的地方,一些文本被包裹在 标签中,这意味着应用某些字体效果。在我的 CSS 中,h6 标记设置为
display:inline;
,因此该段落可以连续运行而不会换行。这除了适用于每个页面上使用的 h6 的第一个实例:第一个元素之前总是有一个换行符。有谁知道为什么/如何防止这种情况?
CSS:
h6 {
font-family:'Courier New',Courier,'Nimbus Mono L',monospace;
font-size:125%;
display:inline;
}
HTML:
As expected, not a lot was accomplished (in this plane) over a
five-day weekend when much of it was devoted tot he college
process. However, I'm down to only a handful of HTML-validation
errors. A couple of which are going to be particularly problematic,
dealing with my new <h6>Lytebox JavaScript</h6> I talked about
earlier: to enable Lytebox on an image, you give it a CSS tag
<h6>data-lyte-options</h6>...
h6 的第二个本质工作正常,但第一个之前有一个换行符。
I have multiple paragraphs of text in an HTML document. Also, at various points, some of the text is wrapped in <h6></h6>
tags, which is meant to apply certain font effects. In my CSS, the h6 tag is set to display:inline;
so the paragraph keeps going continuously without a line break. This works except for the first instance of h6 on each page it is used: there is always a line break before the first element. Does anyone know why/how to prevent this?
CSS:
h6 {
font-family:'Courier New',Courier,'Nimbus Mono L',monospace;
font-size:125%;
display:inline;
}
HTML:
As expected, not a lot was accomplished (in this plane) over a
five-day weekend when much of it was devoted tot he college
process. However, I'm down to only a handful of HTML-validation
errors. A couple of which are going to be particularly problematic,
dealing with my new <h6>Lytebox JavaScript</h6> I talked about
earlier: to enable Lytebox on an image, you give it a CSS tag
<h6>data-lyte-options</h6>...
The second essence of h6 works fine, but there is a line break before the first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
标题元素不能包含在段落内,因为本质上它们被视为块级元素,因此浏览器在到达像标题这样的块级元素时会中断段落。
您的特定 HTML 会被浏览器更改为:
我发现 在 HTML 规范中引用这一事实:
和 另一个讨论块级元素的参考:
解决方案?
问题是您将标题用作通常的段落文本(具有自己的样式)。您应该使用
SPAN
元素来使您的 HTML 有效。如果您只想将文本格式化为代码显示,那么您还可以使用
CODE
元素,该元素应该完全用于此目的。Heading elements can't be contained inside paragraphs, because inherently they're treated as block-level elements hence browsers break paragraphs when they get to a block-level element like heading.
Your particular HTML gets changed to this by browsers:
I found a reference to this fact in HTML specification:
And another reference that talks about block-level elements:
Solution?
The problem is that you're using headings as usual paragraph text (with its own style). You should be using
SPAN
elements instead to make your HTML valid.If all you'd like to do is to format your text to be displayed as code then you can also use
CODE
element which should be used exactly for this purpose.您希望元素内联并应用特殊字体格式,对吧?然后你可以将它们包含在“span”标签中
You want the element to be inline and apply special font formatting right?? Then you can enclose them in a 'span' tag
为什么不创建一个独特的类并根据需要将其应用到您的
标记。您提到有些包裹在 h6 标签中以应用样式。这可以通过
来完成,但您仍然可以使用
常规p 标签。
然后,使用 h6,您可以将它们向左浮动,而不是使用
display:inline
或执行inline-block
,与所有效果几乎相同。然后根据需要对所有样式应用内边距。Why not create a unique class and apply it to your
<p>
tags as needed. You mention some are wrapped in h6 tags to apply styles. That can be done with<p class="onestyle"></p>
and yet you can still have<p></p>
regular p tags.Then with your h6, you can float them left instead of using
display:inline
or doinline-block
, just about the same affect with all. Then apply padding margins as you need to all your styles.尝试使用 CSS 选择器专门针对该实例。不能 100% 确定这会解决问题,但值得一试。
Try using CSS selectors to specifically target that instance. Not 100% sure this will fix it, but worth a try.