HTML 字符间距和跨度
为什么一天中的以下两次显示不一样?我该怎么做才能使第二次看起来像第一次?
<!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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
去掉跨度标签之间的换行符。像这样:
我很难在规范中找到它,但似乎几乎所有浏览器都会采用所有空白并将其“压缩”为单个空格。
这是相关的帖子。
那里接受的答案建议使用 String.Format 来更精确地处理渲染——这可能对您的特定情况有所帮助。
更新:
根据HTML 4规范:
还有一篇有趣的文章将其描述为错误此处。
Get rid of the newlines between span tags. Like this:
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:
There's also an interesting write up describing this as a bug here.