有什么“错误”吗?用这个标记?

发布于 2024-10-26 04:12:05 字数 3097 浏览 5 评论 0原文

这是我正在使用的标记:

<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 &amp; 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 &amp; 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哑剧 2024-11-02 04:12:05

是的,有问题,

    可以位于

  • 的内部,但不能位于其他

    的内部。代码>的。

这是正确的...

<ul>
  <li>
    <ul>  
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </li>
  <li></li>
  <li></li>
  <li></li>
</ul>

Yes, there is something wrong, <ul>'s can be inside of <li>'s, but not other <ul>'s.

This is correct...

<ul>
  <li>
    <ul>  
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </li>
  <li></li>
  <li></li>
  <li></li>
</ul>
你怎么敢 2024-11-02 04:12:05

根据 HTML DTD,您不能有 < code>

    直接位于另一个

      下。您应该将其嵌套在

    • 内。

如果您担心额外的填充/边距,可以使用仅适用于作为

  • 直接子元素的
      元素的规则来删除它们元素:(
  • li > ul { margin: 0; padding: 0 }
    

    或尝试最适合您风格的设置)

    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:

    li > ul { margin: 0; padding: 0 }
    

    (Or experiment with the best setting for your style)

    寻梦旅人 2024-11-02 04:12:05

    下面是正确的方法

    <ul class="menu">
        <li id="planning_menuItem" class="menuItem">
            <a href="/estate_planning/" title="Estate Planning">Estate Planning</a>
        </li>
        <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>
        <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>
    

    BELOW is proper way

    <ul class="menu">
        <li id="planning_menuItem" class="menuItem">
            <a href="/estate_planning/" title="Estate Planning">Estate Planning</a>
        </li>
        <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>
        <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>
    
    会傲 2024-11-02 04:12:05

    正如其他人所说,第二种方法是有效的

    ,这是一个分叉的 jsfiddle 显示一些新的 CSS,这应该有助于

    总结是您希望保留 ul 及其 li 的全宽,没有侧边距或边距,因此重置所有 ul;然后制作 a 的显示块,以便它们填充其父 li 的显示块 - 然后使用 text-indent 创建 a 的缩进外观然后

    ,您可以选择应用“活动或选定”类 - 将其应用于 lia,并且也可以进行任何悬停更改。

    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 their li's full width no side padding or margins, so reset all ul's; then make the a's display block so they fill their parent li's - then use text-indent to create the indented look of the li's

    then however you choose to apply an "active or selected" class - apply it to the li OR a and any hover changes can be made too.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文