回车会在Internet Explorer 8中产生可视空间 [英] Carriage return causes a visual space in Internet Explorer 8
问题描述
我的html代码中的回车导致在Explorer 8中呈现的html中出现可视空间.我猜想这也会影响其他版本.
例如:
<span>
(111)
222-
3333
444444
</span>
看起来像这样:
(111) 222- 3333 444444
第一个括号后面应该只有1个空格,破折号后面应该没有空格,最后3个空格之后也只有1个空格.我喜欢回车以提高代码的可读性,是否有可能保持原状并仍然获取html进行渲染在IE中正确显示?
这是文档类型信息:
<!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">
我实际上是在ASP.NET MVC 2应用程序中执行此操作的,而aspx模板标记非常冗长,这就是为什么我尝试将其分成多行的原因:
<span>
(<%=((Model == null || Model.AreaCode == null) ? "" : Model.AreaCode).PadRight(3)%>)
<%=((Model == null || Model.Prefix == null) ? "" : Model.Prefix).PadRight(3)%>-
<%=((Model == null || Model.Suffix == null) ? "" : Model.Suffix).PadRight(4)%>
<%=(Model == null || Model.Extension == null) ? "" : Model.Extension%>
</span>
这是sprintf
类型函数真正发挥作用的情况.在.NET世界中,这些由String.Format
处理.这是 MSDN文档和您可以这样重写代码:
<span>
<%= String.Format("({0:###}) {1:###}-{2:####} {3}", Model.AreaCode, Model.Prefix, Model.Suffix, Model.Extension); %>
</span>
我对.NET字符串格式的语法有些生疏,因此无法保证该代码段.这是另一个链接:
http://blog.stevex.net/string-formatting-in- csharp/
A carriage return in my html code causes a visual space in the rendered html in Explorer 8. I'm guessing this will affect other versions too.
For example:
<span>
(111)
222-
3333
444444
</span>
looks like this:
(111) 222- 3333 444444
There should be only 1 space after the first bracket, no space after the dash and only 1 space after the last 3. I like the carriage returns for code readability, is it possible go keep then and still get the html to render properly in IE?
Here's the doctype information:
<!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">
Edit:
I'm actually doing this in an ASP.NET MVC 2 app, and the aspx template markup is quite verbose which is why I've tried to seperate it into multiple lines:
<span>
(<%=((Model == null || Model.AreaCode == null) ? "" : Model.AreaCode).PadRight(3)%>)
<%=((Model == null || Model.Prefix == null) ? "" : Model.Prefix).PadRight(3)%>-
<%=((Model == null || Model.Suffix == null) ? "" : Model.Suffix).PadRight(4)%>
<%=(Model == null || Model.Extension == null) ? "" : Model.Extension%>
</span>
This is a scenario where sprintf
type functions really shine. In the .NET world these are handled by String.Format
. Here's the MSDN documentation and you could rewrite the code something like this:
<span>
<%= String.Format("({0:###}) {1:###}-{2:####} {3}", Model.AreaCode, Model.Prefix, Model.Suffix, Model.Extension); %>
</span>
I'm a little rusty on the .NET string format syntax, so no guarantees on that code snippet. Here's another link:
http://blog.stevex.net/string-formatting-in-csharp/
这篇关于回车会在Internet Explorer 8中产生可视空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!