Created
October 10, 2012 19:56
-
-
Save matthewcopeland/3868007 to your computer and use it in GitHub Desktop.
Eliminate html whitespace with this little trick. Plus the simplified version in haml. Putting the closing-tag and next opening-tag on the same line kills the whitespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| <p>These divs have white space between them.</p> | |
| </div> | |
| <div> | |
| <p>Because html naturally creates whitespace on the line-breaks.</p> | |
| </div> | |
| <!-- with comments --> | |
| <div> | |
| <p>These divs have white space between them.</p> | |
| </div><!-- html inserts whitespace between me --> | |
| <div><!-- and me --> | |
| <p>Because html naturally creates whitespace on the line-breaks.</p> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div> | |
| <p>These divs DO NOT have white space between them.</p> | |
| </div><div> | |
| <p>Because no line-breaks exist between them.</p> | |
| </div> | |
| <!-- Again. This time with comments --> | |
| <div> | |
| <p>These divs DO NOT have white space between them.</p> | |
| </div><div><!-- html can't come between us. aww. --> | |
| <p>Because no line-breaks exist between them.</p> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %div | |
| %p This is normal haml and will out the same html-markup as the above file: 01_has_whitespace.html | |
| %div | |
| %p Because html naturally creates whitespace on the line-breaks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| / By using the alligator, '>' | |
| / this haml will output the same html-markup as shown in 02_doesnt_have_whitespace.html | |
| / For more details, see | |
| / http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_ | |
| %div> | |
| %p These divs do not have any whitespace between them. | |
| %div> | |
| %p These divs do not have any whitespace between them. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment