gpt4 book ai didi

html - 明确与隐含段落的奇怪之处

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:45 25 4
gpt4 key购买 nike

我正在尝试使用 HTML 和 CSS 看看我是否可以制作一个 LaTeX Logo ,该 Logo 可以与其余文本(不是图像)一起缩放和着色。我可以用内联 block 来做到这一点 <div> 如果它没有包含在一个段落中。如果我添加 <p></p>标签,它打破了。带有显式段落标记的段落和没有显式段落标记的段落有什么区别?这会被某些 HTML 文档类型修复吗?

<!doctype html>
<html>
<head>
<title>Test logos</title>
</head>
<body style="font: 12px Arial,sans-serif;">
1. div inline-block, works fine<br>
So as a helpful reminder, I thought I would gather some helpful information here to
help both veterans of these forums and new users lean how best to use these forums.
Where are the forum rules?
<div style="display: inline-block; position: relative;
border: 1px solid blue; /* just for debug */
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<div style="left: 0em; bottom: -0.6ex; position: absolute;">L</div>
<div style="left: 0.7em; bottom: 0.3ex; position: absolute; font-size: 50%;
font-weight: bold;">A</div>
<div style="left: 0.6em; bottom: -0.6ex; position: absolute;">&Tau;</div>
<div style="left: 1.35em; bottom: -1.25ex; position: absolute; font-size: 80%;
font-weight: 600;">&Epsilon;</div>
<div style="left: 1.63em; bottom: -0.6ex; position: absolute; ">&Chi;</div>
</div>
rules!
You can find the forum rules via this thread:
Helping Each Other and Keeping Posts Respectful.
<hr>
<p>
2. p div inline-block, div OK, but /p inserted before it, so line break and gap
before div<br>
So as a helpful reminder, ...
<div style="display: inline-block; position: relative;
border: 1px solid blue;
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<< see nested <div>s above >>
</div>
rules!...
</p>
<hr>
3. span inline-block, works fine<br>
So as a helpful reminder, ...
<span style="display: inline-block; position: relative;
border: 1px solid blue;
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<< see nested <div>s above >>
</span>
rules! ...
<hr>
<p>
4. p span inline-block, block empty, /span and /p inserted after span<br>
So as a helpful reminder, ...
<span style="display: inline-block; position: relative;
border: 1px solid blue;
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<< see nested <div>s above >>
</span>
rules! ...
</p>
<hr>
5. span block, block OK, but has line breaks before and after<br>
So as a helpful reminder, ...
<span style="display: block; position: relative;
border: 1px solid blue;
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<< see nested <div>s above >>
</span>
rules! ...
<hr>
<p>
6. p span block, block empty, /span /p inserted, divs elsewhere, break
before/after block<br>
So as a helpful reminder, ...
<span style="display: block; position: relative;
border: 1px solid blue;
font-family: Times-New-Roman,serif; height: 2ex; width: 2.30em;">
<< see nested <div>s above >>
</span>
rules! ...
</p>
</body>
</html>

第一种和第三种情况(没有 <p> 标签)似乎工作正常。第三个在跨度内有 div,但似乎接受它。第四种和第六种情况( <span> block 或内联 block ,带 <p> )得到 </span></p>自动插入,因此 span 内容为空白,div 漂浮在其他地方。第二种情况与第一种情况相同,除了 <p>。 , 和一个 </p>在 LaTeX Logo block 之前自动插入(连同边距)。第五个案例类似于第三个案例,除了它是一个 block 而不是一个内联 block (都是跨度)并且在 Logo block 之前和之后插入了中断。

FF30(我的主要平台)、Chrome 和 IE11 的行为方式几乎相同。简而言之,为什么添加段落标签会带来如此大的行为变化?它似乎不仅仅是一个带有顶部和底部边距的简单 block 元素!

最佳答案

主要是,您遇到的事实是 <div> <p> 内不允许使用标签标签。并且 <span> 中应该只有内联元素标签。不同的浏览器可能会将此解释为您要放置 </p>并为您插入各种标签。另外,当它是 display:block 时,它将占用包含元素的宽度,在本例中为 <body> ,这就是为什么会有看起来像换行符的原因。

查看规范,Grouping ElementsLines and Paragraphs .(以下是这些部分的引述。)

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

 <!ELEMENT SPAN - - (%inline;)*    

关于html - 明确与隐含段落的奇怪之处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24377975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com