我正在使用 :first-line { line-height:0px; }
隐藏 block 语句中的空第一行
奇怪的是,如果我在 XHTML strict 中定义 doctype,Firefox 会忽略此语句并打印空行(可通过边框看到)
我验证了我的 quellcode 并使用 Firefox 的 webdeveloper 来检查,如果有任何错误,但他们告诉我没有错误
(剥离的)示例 quellcode 是:
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>T</title>
<style type="text/css"><!--
.v { white-space:pre; display:inline-block; border:1px solid black; }
.v:first-line { line-height:0px; }
--></style>
</head><body>
<p class="v">
Foo
Bar
</p>
</body></html>
我的代码和其他浏览器(我已经测试过 Opera、Gnome、Safari)有什么问题只是忽略了严格,还是 Firefox 错误地遵守了严格?
最佳答案
我不确定这是否真的是一个错误......
我猜 :first-line
选择器的内部无法识别其中只有一个换行符的空行,但我不确定这是否需要。 W3C Recommendations 中没有任何内容可以证明这种行为是对是错:
CSS 2.1 规范:
5.12.1 The :first-line pseudo-element
The :first-line pseudo-element applies special styles to the contents of the first formatted line of a paragraph.
--
16.6 White space: the 'white-space' property
'white-space'
...
pre This value prevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.
如果您正在动态生成 HTML 代码,只需在输出之前尝试消除空行。这是我目前唯一能给出的建议。
关于firefox - CSS - 行高 :0 ignored in XHTML strict in Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9679985/