0

When coding in HTML & PHP, line breaks get interpreted as a space character. This can be problematically when using a list in order to achieve a horizontal menu because the space changes the padding unpredictably. I use this workaround for this:

Note: The <li> elements will have a display: inline(-block); property.

<ul>
    <li>...</li><?php
    ?><li>...</li><?php
    ?><li>...</li><?php
    ?><li>...</li><?php
    ?><li>...</li>
</ul>

This is really sad. I don't think it is supposed to be that way. I also don't want to mess up the code in a different way by say... add both </li> and the next <li> on one line (which is essentially the same as above).

Question: Is there a best practice solution for this?

bytecode77
  • 12,331
  • 27
  • 101
  • 126
  • Try using
    tag in html
    – parth6 Oct 19 '14 at 07:38
  • That is perfectly fine. It simply is a fact that whitespaces (whichever) have no layouting effect in html markup. That is by design. Instead you have to use explicit linebreaks or styling for the effect you desire. – arkascha Oct 19 '14 at 07:38
  • If you are trying to just have the source have a line break, maybe use "\r\n". As @arkascha says, it shouldn't effect the actual display if they run together in the source....provided this is infact what you are referring to... – Rasclatt Oct 19 '14 at 07:38
  • But the white space separates the `
  • ` elements by the width of its character. How do you *style* that away?
  • – bytecode77 Oct 19 '14 at 07:41
  • Asking for “best practice solution” tends to be primarily opinion-based, especially when no criteria have been set or they are esthetical (what the code looks like). – Jukka K. Korpela Oct 19 '14 at 07:45
  • The criteria is to avoid the php tags used in the example and get a result without padding producing white spaces. – bytecode77 Oct 19 '14 at 07:47