有什么“错误”吗?用这个标记?
这是我正在使用的标记:
<ul class="menu">
<li id="planning_menuItem" class="menuItem"><a href="/estate_planning/" title="Estate Planning">Estate Planning</a></li>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem"><a href="/estate_planning/last_will_and_testament.htm" title="Last Will and Testaments">Last Will & Testament</a></li>
<li id="poa_menuItem" class="subMenuItem"><a href="/estate_planning/power_of_attorney.htm">Power Of Attorney</a></li>
<li id="livingWill_menuItem" class="subMenuItem"><a href="/estate_planning/living_will.htm">Living Will</a></li>
<li id="trusts_menuItem" class="subMenuItem"><a href="/estate_planning/trusts.htm">Trusts</a></li>
</ul>
<li id="probate_menuItem" class="menuItem">
<a href="probate_administration.htm" title="Estate Administration">Estate Probate Administration</a>
</li>
<li id="realEstate_menuItem" class="menuItem"><a href="#" title="Real Estate Transactions">Real Estate</a></li>
<li id="medicaid_MenuItem" class="menuItem"><a href="#" title="">Medicaid</a></li>
<li id="guardianships_menuItem" class="menuItem"><a href="#" title="">Guardianships</a></li>
</ul>
将“ul”(class=subMenu)放在列表中间而不具有自己的 li 标记是否有任何风格上的错误?这个特殊的标记解决了我的问题,但我至少想知道我是否违反了某些标准或约定。
另一种方法如下,但它不适用于我的特定任务。
<ul class="menu">
<li id="planning_menuItem" class="menuItem"><a href="/estate_planning/" title="Estate Planning">Estate Planning</a>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem"><a href="/estate_planning/last_will_and_testament.htm" title="Last Will and Testaments">Last Will & Testament</a></li>
<li id="poa_menuItem" class="subMenuItem"><a href="/estate_planning/power_of_attorney.htm">Power Of Attorney</a></li>
<li id="livingWill_menuItem" class="subMenuItem"><a href="/estate_planning/living_will.htm">Living Will</a></li>
<li id="trusts_menuItem" class="subMenuItem"><a href="/estate_planning/trusts.htm">Trusts</a></li>
</ul>
</li>
<li id="probate_menuItem" class="menuItem">
<a href="probate_administration.htm" title="Estate Administration">Estate Probate Administration</a>
</li>
<li id="realEstate_menuItem" class="menuItem"><a href="#" title="Real Estate Transactions">Real Estate</a></li>
<li id="medicaid_MenuItem" class="menuItem"><a href="#" title="">Medicaid</a></li>
<li id="guardianships_menuItem" class="menuItem"><a href="#" title="">Guardianships</a></li>
</ul>
谢谢!
Here is the markup I'm using:
<ul class="menu">
<li id="planning_menuItem" class="menuItem"><a href="/estate_planning/" title="Estate Planning">Estate Planning</a></li>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem"><a href="/estate_planning/last_will_and_testament.htm" title="Last Will and Testaments">Last Will & Testament</a></li>
<li id="poa_menuItem" class="subMenuItem"><a href="/estate_planning/power_of_attorney.htm">Power Of Attorney</a></li>
<li id="livingWill_menuItem" class="subMenuItem"><a href="/estate_planning/living_will.htm">Living Will</a></li>
<li id="trusts_menuItem" class="subMenuItem"><a href="/estate_planning/trusts.htm">Trusts</a></li>
</ul>
<li id="probate_menuItem" class="menuItem">
<a href="probate_administration.htm" title="Estate Administration">Estate Probate Administration</a>
</li>
<li id="realEstate_menuItem" class="menuItem"><a href="#" title="Real Estate Transactions">Real Estate</a></li>
<li id="medicaid_MenuItem" class="menuItem"><a href="#" title="">Medicaid</a></li>
<li id="guardianships_menuItem" class="menuItem"><a href="#" title="">Guardianships</a></li>
</ul>
Is there anything stylistically wrong about having that "ul" (class=subMenu) in the middle of a list without it having it's own li tag? This particular mark-up solves my problem, but I want at least be aware of whether I'm breaking some standard or convention.
The alternative is as follows, but it doesn't work for my particular task.
<ul class="menu">
<li id="planning_menuItem" class="menuItem"><a href="/estate_planning/" title="Estate Planning">Estate Planning</a>
<ul class="subMenu">
<li id="will_menuItem" class="subMenuItem"><a href="/estate_planning/last_will_and_testament.htm" title="Last Will and Testaments">Last Will & Testament</a></li>
<li id="poa_menuItem" class="subMenuItem"><a href="/estate_planning/power_of_attorney.htm">Power Of Attorney</a></li>
<li id="livingWill_menuItem" class="subMenuItem"><a href="/estate_planning/living_will.htm">Living Will</a></li>
<li id="trusts_menuItem" class="subMenuItem"><a href="/estate_planning/trusts.htm">Trusts</a></li>
</ul>
</li>
<li id="probate_menuItem" class="menuItem">
<a href="probate_administration.htm" title="Estate Administration">Estate Probate Administration</a>
</li>
<li id="realEstate_menuItem" class="menuItem"><a href="#" title="Real Estate Transactions">Real Estate</a></li>
<li id="medicaid_MenuItem" class="menuItem"><a href="#" title="">Medicaid</a></li>
<li id="guardianships_menuItem" class="menuItem"><a href="#" title="">Guardianships</a></li>
</ul>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,有问题,
可以位于
的内部,但不能位于其他
的内部。代码>的。
这是正确的...
Yes, there is something wrong,
<ul>
's can be inside of<li>
's, but not other<ul>
's.This is correct...
根据 HTML DTD,您不能有 < code>
直接位于另一个
下。您应该将其嵌套在
内。
如果您担心额外的填充/边距,可以使用仅适用于作为
直接子元素的
元素的规则来删除它们元素:(
或尝试最适合您风格的设置)
According to the HTML DTD, you cannot have a
<ul>
directly under another<ul>
. You should nest it inside a<li>
.If you're worried about the additional padding/margins, you can remove them with a rule that only applies to
<ul>
elements as direct children of<li>
elements:(Or experiment with the best setting for your style)
下面是正确的方法
BELOW is proper way
正如其他人所说,第二种方法是有效的
,这是一个分叉的 jsfiddle 显示一些新的 CSS,这应该有助于
总结是您希望保留
ul
及其li
的全宽,没有侧边距或边距,因此重置所有ul
;然后制作a
的显示块,以便它们填充其父li
的显示块 - 然后使用text-indent
创建 a 的缩进外观然后,您可以选择应用“活动或选定”类 - 将其应用于
li
或a
,并且也可以进行任何悬停更改。as others have said the second way is valid
here's a forked jsfiddle showing some new CSS which should help
summary is that you want to keep the
ul
's and theirli
's full width no side padding or margins, so reset allul
's; then make thea
's display block so they fill their parentli
's - then usetext-indent
to create the indented look of the li'sthen however you choose to apply an "active or selected" class - apply it to the
li
ORa
and any hover changes can be made too.