List of tags in HTML - plain comma separated list or ul with some css?
On a website I'm creating I'm displaying some tags for each news entry.
Now there are two ways to display the tags: simply using a string tag1, tag2, tag3
or putting them in a list <ul><li>tag1</li><li>tag2</li><li>tag3</li></ul开发者_如何学Go>
.
Of course I would style this list so it looks exactly like the plain string: http://jsfiddle.net/ThiefMaster/YKFH5/
My question is now: Which of these methods would you use and why? From what I know the necessary CSS for the list method is widely supported and in older browsers the only thing missing would be the commas.
It depends on what you're trying to accomplish. If you just want to list the items, there's nothing wrong with your first method, just listing the text out. The reason to go the other route would be if you want to style each item, or for some other reason separate them for clicking, hovering, etc...
Demo with hover effect: http://jsfiddle.net/Jaybles/YKFH5/3/
I would go with the UL option, as that seems more semantic. Of course, if you don't ever plan on doing anything with those tags rather than just list them, it doesn't really matter either way.
If your going to make a list, in order to format it as if it were a plain string, why not just used a plain string? You can dynamically format that string anywhere you like, very easily, with no css required.
精彩评论