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?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
It's not valid HTML to use
<li>
outside anol
,ul
, ormenu
element. It's much better to assign a class to theul
element:And then use CSS to remove the margin and padding:
This might not answer your question directly, but I'm wondering if you use a CSS reset?
I have found since I started using them, I don't encounter those sort of issues any more. http://developer.yahoo.com/yui/3/cssreset/
Also, another thing to consider is that your nav doesn't have to be in
<li>
's (necessarily). Why not make them just links in a<div class="nav">
Hope this helps!
You can, and almost all browsers will recognize it, but it's not good, semantic HTML, and won't validate.
Try removing the margin and padding for the
ul
in your stylesheet:The UL and LI combination are one of the most liberally interpreted elements in all of HTML. Meaning they tend to look wildly different depending on which browser you use. As others suggest, reset the margins and paddings to 0. But you should be doing this anyway in a reset stylesheet, so that you catch the other elements that display differently across browsers.
It's probably working in browsers because browsers are too forgiving, but that's not valid says the validator:
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:In case you're wondering what
padding
is, see it here.