忽略 HTML 中的空格 [英] Ignore whitespace in HTML
本文介绍了忽略 HTML 中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML/CSS 中是否有任何内容告诉浏览器完全忽略空格?
Is there anything in HTML/CSS that tells the browser to ignore whitespace completely?
很多时候,当您想将两个图像并排放置时 - 您拼命地尝试保持 HTML 可读,但浏览器在它们之间放置了一个空格.
So many times when you want to put, say, two images next to each other - you try desperately to keep the HTML readable, but the browser puts a space between them.
所以,而不是像这样:
<img src="images/minithing.jpg" alt="my mini thing" />
<img src="images/minithing.jpg" alt="my mini thing" />
<img src="images/minithing.jpg" alt="my mini thing" />
<img src="images/minithing.jpg" alt="my mini thing" />
你最终得到这个
<img src="images/minithing.jpg" alt="my mini thing" /><img src="images/minithing.jpg" alt="my mini thing" /><img src="images/minithing.jpg" alt="my mini thing" /><img src="images/minithing.jpg" alt="my mini thing" />
这太可怕了!
推荐答案
哦,你真的可以用 一行 CSS:
#parent_of_imgs { white-space-collapse: discard; }
缺点,你问?还没有浏览器实现了这个非常有用的功能(想想一般的内联块).:-(
Disadvantage, you ask? No browser has implemented this extremely useful feature (think of inline blocks in general) yet. :-(
我时不时做的,虽然夜深了难看,但就是用评论:
What I did from time to time, although it's ugly as the night is dark, is to use comments:
<p><!--
--><img src="." alt="" /><!--
--><img src="." alt="" /><!--
--><img src="." alt="" /><!--
--><img src="." alt="" /><!--
--></p>
这篇关于忽略 HTML 中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文