简体   繁体   English

在href之前img标签之后的神秘空间

[英]Mysterious space after img tag before href

I have a mysterious space coming up between an img and href tag. 我在img和href标签之间有一个神秘的空间。 My link, forwarding to a word document is preceded by a space after a small icon, that should actually not be there. 我的链接,转发到word文档前面有一个小图标后面的空格,实际上不应该在那里。 Curiously the space only appears if the extension of the link is .doc but disappears when I change it to .docx, or to an .html extension. 奇怪的是,只有当链接的扩展名为.doc时才会出现空格,但是当我将其更改为.docx或扩展名为.html时,该空格会消失。

This code... 这段代码......

<img  src="../images/icon/wordicon_small.gif" />
    <a href="../docs/template.doc" target="_blank">template</a></p>
<br/>
 <img  src="../images/icon/wordicon_small.gif" />
 <a href="../docs/template.docx" target="_blank">template</a>   

transalates into: 转化为:

http://postimg.org/image/59fam7ny1/

I am really confused. 我真的很困惑。 Don't even know where to begin. 甚至不知道从哪里开始。 My CSS specifications seem ok and did not arouse suspicion on my side. 我的CSS规范似乎没问题,并没有引起我的怀疑。 Anybody has any idea what the problem could be? 任何人都知道问题可能是什么?

You have a few spaces before your first <a href> 在第一次<a href>之前,您有几个空格

By removing the spaces the problem should be fixed. 通过删除空格,问题应该得到解决。

If the spaces are generated from a script to html then you need to check the differences of handling doc and docx links between a few statements in your script. 如果从脚本生成空格到html,那么您需要检查脚本中几个语句之间处理doc和docx链接的差异。

You have white space characters (spaces, line breaks, etc.) between the images and links, so there should be a space between them, but that should only be a single space, just like between the second set of elements. 在图像和链接之间有空格字符(空格,换行符等),因此它们之间应该有一个空格,但这应该只是一个空格,就像在第二组元素之间一样。 Multiple white space characters in a row collapse into a single space. 一行中的多个空白字符会折叠到一个空格中。

Try to retype the spaces between the first image and link. 尝试重新键入第一个图像和链接之间的空格。 My guess is that you have a non-breaking space (ASCII 160) in there somewhere. 我的猜测是你在那里有一个不间断的空间(ASCII 160)。 That doesn't count as a white space character, so it doesn't collapse into a single space with the spaces and line breaks. 这不算作空白字符,因此它不会折叠成具有空格和换行符的单个空格。

Sometimes non-breaking spaces are used to cause extra spacing between text or elements, as they don't collapse, for example: 有时不间断的空格会导致文本或元素之间产生额外的间距,因为它们不会崩溃,例如:

Price: &nbsp; &nbsp; &nbsp; &nbsp; $0.99

displays as: 显示为:

Price: $0.99 价格:0.99美元

The &nbsp; &nbsp; is the HTML entity for the non-breaking space, but you can also type it as a regular character. 是不间断空格的HTML实体,但您也可以将其键入常规字符。 How you do that depends on the editor, but ctrl+space is used in some. 你如何做到这一点取决于编辑器,但在某些情况下使用ctrl + space。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM