So I had a list that looked like this:
the orange lines are just outlines for reference |
Well, obviously it is a CSS problem. So I spent over an hour comparing the individual values of all the computed styles, of the list elements and the box element, and for good measure all the surrounding elements, too. The new items and the PHP-generated items were identical in every way. So not a CSS problem, then. Dammit.
Thank the gods for StackOverflow. I asked, and there did I receive the answer. See, I'm a bit of a neat freak. I like my HTML properly indented. I just started a new job where my employer insists on all the tags being on the same level, with no tabs or whitespaces before them:
<div> <p>Some text</p> <div> <div> <p>Some more text, woohoo!</p> </div> </div> <div> <h3>Wait...</h3> <div> <p>What the hell div am I in now?</p> </div> <div> <div>Oh, another div. Hi!</div> </div> </div> </div>
Who can read that? My boss, incidentally, is perennially plagued with a problem - his opening tags often don't have closing tags. This drives him crazy. I have not yet pointed out the possible correlation between the two issues, but I feel this vindicates my choice to indent. Show me a man who will tell me this is not easier to read, and I will show you the palm of my hand approaching the upside of your head at a non-fatal but certainly startling velocity:
<div> <p>Some text</p> <div> <div> <p>Some more text, woohoo!</p> </div> </div> <div> <h3>Wait...</h3> <div> <p>What the hell div am I in now?</p> </div> <div> <div>Oh, another div. Hi!</div> </div> </div> </div>
Anyway, the point of all this is that while indentation is obviously the right way to go, it can cause unexpected issues with inline elements.
<div> <p>Some text to explain that <span>the randomly-generated word is </span> <span id="randomword">jugularistic</span> <span>, but if you want, we can change it.</span> </p> <input type="button" onclick="getRandomWord();"> </div>
See, this is nicely and logically indented so I can see what the hell is going on. The real example was much more complicated, of course. The problem is the whitespace before each span. The browser seems to interpret it as being part of the <p> tag contents, because it lies between inline elements.
But I knew this! I've known it since I started learning HTML, before I even knew what Javascript was, way back when Netscape was a name ordinary people might have had a chance of knowing. Inline vs. block. So bloody simple.
Of course, the real lesson is I probably need to structure my documents better. Oh, well.
Here is the StackOverflow Q&A: http://stackoverflow.com/questions/12853619/dynamically-inserted-content-creates-odd-margin
No comments:
Post a Comment