Is using
  • without enclosing
      tags dangerou
  • 2019-01-07 23:12发布

    What are the dangers of inserting <li>...</li> into a page without enclosing the item(s) in a <ul> block? For example:

    <div style="border:solid 1px red;">
        <li>Item</li>
        <li>Another Item</li>
        <li>Yet Another Item</li>
    </div>
    

    Validation is the least of my concerns, I'm wondering what this might break in browsers for the end user's ability to view the page as intended.

    12条回答
    一夜七次
    2楼-- · 2019-01-07 23:39

    Unexpected rendering behaviors on different browsers ? SEO ?

    查看更多
    干净又极端
    3楼-- · 2019-01-07 23:42

    As a web designer/developer you know you're way off when you start writing HTML that even Frontpage or Microsoft Word wouldn't generate.

    Adhering to standards is a two-way street. If we want browser developers to create fast, reliable and consistent rendering engines we need to meet them half-way by creating consistent, clean and well-formed HTML.

    查看更多
    一夜七次
    4楼-- · 2019-01-07 23:43

    Dangerous? It won't blow anything up. It may cause issues if the layout is in any way important to you.

    You just won't know how the browser will render it.

    查看更多
    等我变得足够好
    5楼-- · 2019-01-07 23:48

    This is echoing everybody else's answer, in part: with any markup, there's an empirical question of whether it works or not on the browsers that you are testing it on. You tested it on all your browsers, and your happy. That's cool and is a huge part of the work.

    But beyond that, there's also the hypothetical question of how well it might work on browser-platform combinations that you haven't tested, either because:

    1. you didn't include them in the test set
    2. they don't exist yet or
    3. they're not available for testing (web-crawlers, for instance)

    For this set, which always becomes relevant sooner or later, you should follow standards -- when possible -- and use the enclosing UL or OL tags (in this case).

    It's also worth mentioning that it makes the LI tags easier to track down if you are doing scripting, or if someone is doing scripting on your page (e.g., Greasemonkey).

    查看更多
    成全新的幸福
    6楼-- · 2019-01-07 23:49

    I cant really imagine why you wouldnt want to put the <ul> or <ol> tags in, they define the list. You then have control on how the list is displayed, not leaving it for the browser to decide, which is important. Missing them out is just writing invalid markup, yeah it will work in some browsers, but id definitely keep them in.

    查看更多
    来,给爷笑一个
    7楼-- · 2019-01-07 23:50

    It would be up to the browser's implementation to decide what to do with it. If you really want to do this, test it out in all the browsers you want to support before using it.

    Also note that the browsers' behaviours might change in the future.

    查看更多
    登录 后发表回答