Why do we always use <ul>
to make navigation why not <ol>
? While we can use both technically.
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
There isn’t much practical difference between the two.
Using
<ol>
suggests that it’s important the list remain in the same order. For most navigation on the web, the order of the navigation items doesn’t matter.An exception would be navigation within a process, e.g. if you’re taking the user through a 3-step purchase process, and are giving them navigation to move to any step. An ordered list would be appropriate there, as the steps come one after the other, e.g.
Note that in HTML5, you can and should wrap any major navigation block, whether it uses
<ul>
,<ol>
or something else, in the<nav>
element.Because semantically
ul
makes more sense if you don't care about the order of menu items.If you need items to be somehow numbered or when the order has meaning, then we use
ol
.If you're not interested in semantic markup but only in appearance, you can use either. Or even neither, use divs and spans and anything else to achieve the needed appearance.
well, maybe you always do it, but "we" doesn't mean anything here.
It depends if your list is ORDERED or UNORDERED. That's all.
I think this is a classic example of why you should separate style from content. As Developer Art, if you don't care about semantic markup, then you can use either one or the other or something completely different at all.
<ul> and <ol> will be rendered differently as a default, with ordered lists numbered (or with letters) indicating the order and unordered lists with bullets or something similar. However, since I assume that about every web page uses styling, this doesn't necessarily matter.
I'd use ordered lists when the order is actually important for the content. Table of contents, enumerations, or any lists where the order is important for the content represented are examples. For most everything else I use unordered lists. (So, you could say that I always use unordered lists unless I have a good reason to use an ordered list.)
Though navigation items do have an order, this is more a visual thing of how navigation is represented and thus can be most easily achieved by using a simple unordered list and appropriate styling. I do not think that navigation items do have an order based on the content. I would argue that although the order is also important for navigation, it's not that important content-wise.
After all, it's a matter of how you see the content and shouldn't make that much difference when it comes to the actual implementation.
why do we use
<strong>
when we can use<em>
? (they look differently by default, but that's another story. ol and ul also have different bullets/numbers by default)navigation items are usually without any specific order, and thus an unorderd list
<ul>
is used instead of an ordered one<ol>
If the order of your menu is semantically important — if, for example, it’s logical that tags comes after questions, then users and badges — then you should use
<ol>
instead of an unordered list.