Ignore whitespace in HTML

This question already has an answer here:

  • How do I remove the space between inline-block elements? 32 answers

  • Oh, you can really easy accomplish that with a single line of 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>
    

    您可以将容器font-size设置为0 ,并且white-space消失!


    The browsers does ignore whitespace in most cases when it's next to a block element.

    The problem with images (in this case) is that they are inline elements, so while you write them on separate lines, they are actually elements on the same line with a space between them (as the line break counts as a space). It would be incorrect for the browser to remove the spaces between the images, writing the image tags with line breaks between them should be handled the same way as writing the image tags on the same line with spaces between them.

    You can use CSS to make the images block elements and float them next to each other, that solves a lot of problems with spacing, both the space between the images and the spacing on the text line below images.

    链接地址: http://www.djcxy.com/p/88874.html

    上一篇: 为什么HTML5输入类型的日期时间已从支持它的浏览器中删除?

    下一篇: 忽略HTML中的空格