Lets assume for the sake of this question, I have a container element, with three columns inside that container and with a right margin of 10 pixels, on the third column I want to set the right margin to 0 pixels.
Now there are two ways I can do this, I can do this using jquery to select the nth-child, but I can also do this server-side using a simple loop count to get the third element. My question is what is the recommended practice of achieving something like this? Doing it server side means, the layout works perfect even if javascript is disabled on the users browser. However, the idea of using server side code for these kind of cosmetic reasons, may not be ideal prac开发者_开发百科tice, and server-side could should be used strictly for functionality.
I'd like to know what peoples views are on this.
What about using CSS :last-child
?
#container div:last-child { margin-right: 0; }
If you really care about IE6, you can add some kind of class (like final-column
) in the server-side code for the last column, but no inline styles.
#container div:last-child, #container div.final-column { margin-right: 0; }
Finally, don't use Javascript for styling purposes.
If the layout is not gonna be changed after rendered, I believe using server-side HTML generation should be a more robust way.
精彩评论