I have a navigation that I am using a list for. I have it in a <ul>
, but that is messing up my UI because it has weird automatic margins. I tried without the <ul>
and they seem to work. Would this work across all browsers? Is this legal? Anybody else done this before?
Answer: yes it does, but with: ol or menu, that's all!
The ol element is used when the list is ordered and the ul element is used when the list is unordered. Definition lists ( dl ) are used to group terms with their definitions. Although the use of this markup can make lists more readable, not all lists need markup.
The <ul> tag defines an unordered (bulleted) list. Use the <ul> tag together with the <li> tag to create unordered lists. Tip: Use CSS to style lists.
It's not valid HTML to use <li>
outside an ol
, ul
, or menu
element. It's much better to assign a class to the ul
element:
<ul class="nav">
And then use CSS to remove the margin and padding:
.nav {
margin: 0;
padding: 0;
}
It's probably working in browsers because browsers are too forgiving, but that's not valid says the validator:
Document type does not allow element "li" here; missing one of "ul", "ol", "menu", "dir" start-tag
Well, you can remove customize margins in CSS. That's your only solution. Generally, you can remove it on all <ul>
tags in the documents by:
ul {
margin: 0;
padding: 0;
}
In case you're wondering what padding
is, see it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With