firefox - CSS - 行高 :0 ignored in XHTML strict in Firefox

标签 firefox xhtml css strict

我正在使用 :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/

相关文章:

java - 小部件的所有实例的 GWT setStylePrimaryName

html - 元素未在 Firefox 中显示,但在其他导航器中正常

java - 如何刷新 Selenium Java Webdriver 中的挂起页面?

css - 适用于所有设备的可重用 html 包装器

html - 为什么我的 HTML 结构不适用于 CSS 网格布局?

css - 无法在 Apache 2.2 中显示 CSS 背景图片

html - Mozilla Firefox 中的线性渐变工件

javascript - 语法错误 : '[object HTMLDocument]' is not a valid selector in firefox

javascript - 加载时聚焦输入框

php - 以编程方式从图像文件和/或 PSD 中提取图案