HTML 字符间距和跨度

发布于 2024-10-06 16:05:04 字数 548 浏览 0 评论 0原文

为什么一天中的以下两次显示不一样?我该怎么做才能使第二次看起来像第一次?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
    <div>
     8:00
                <span>8</span>
                <span>:</span>
                <span >00</span>
    </div>            

</body>
</html>

Why are the following 2 times of day not displayed the same and what can I do to make the second time look like the first?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
    <div>
     8:00
                <span>8</span>
                <span>:</span>
                <span >00</span>
    </div>            

</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱贱哒 2024-10-13 16:05:04

去掉跨度标签之间的换行符。像这样:

<div>
 8:00
            <span>8</span><span>:</span><span >00</span>
</div>     

我很难在规范中找到它,但似乎几乎所有浏览器都会采用所有空白并将其“压缩”为单个空格。

这是相关的帖子

那里接受的答案建议使用 String.Format 来更精确地处理渲染——这可能对您的特定情况有所帮助。

更新:

根据HTML 4规范

SGML(参见 [ISO8879],第 7.6.1 节)
指定换行符
紧接在开始标记之后必须
被忽略,换行符也必须被忽略
紧接在结束标记之前。这
适用于所有 HTML 元素,无需
异常。

还有一篇有趣的文章将其描述为错误此处

Get rid of the newlines between span tags. Like this:

<div>
 8:00
            <span>8</span><span>:</span><span >00</span>
</div>     

I'm hard pressed to find it in the spec, but it appears that virtually all browsers take all white spaces and "compress" it down to a single space.

Here's a related SO post.

The accepted answer there recommends using String.Format to handle rendering more precisely -- this may help in your particular situation.

Update:

According the HTML 4 spec:

SGML (see [ISO8879], section 7.6.1)
specifies that a line break
immediately following a start tag must
be ignored, as must a line break
immediately before an end tag. This
applies to all HTML elements without
exception.

There's also an interesting write up describing this as a bug here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文