我们可以在中使用中的任何其他TAG吗?

时间:2022-01-14 01:12:24

Can we use any other TAG in <ul> along with <li>?

我们可以在

    中使用
  • 中的任何其他TAG吗?

  • 中的任何其他标签吗?

like

喜欢

<ul>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
Some text here or <p>Some text here<p> etc
<li>item 1</li>
</ul>

9 个解决方案

#1


44  

For your code to be valid you can't put any tag inside a <ul> other than an <li>.

为了使您的代码有效,您不能将任何标记放在除

  • 之外的
      中。

  • 之外的中。
  • You can however, put any block level element inside the <li>, like so:

    但是,您可以将任何块级元素放在

  • 中,如下所示:

  • 中,如下所示:
  • <ul>
            <li>
                <h2>...</h2>
                <p>...</p>
                <p>...</p>
            </li>
    </ul>
    

    #2


    10  

    According to the W3C Recommendation, the basic structure of a list must be:

    根据W3C建议书,列表的基本结构必须是:

    <UL>
       <LI> ... first list item...
       <LI> ... second list item...
       ...
    </UL>
    

    You can put p tags only inside of li tags, not as direct children of ul. The W3C Recommendation expressly states:

    你可以只在li标签内部放置p标签,而不是ul的直接子节点。 W3C建议明确指出:

    lists are made up of sequences of list items defined by the LI element

    列表由LI元素定义的列表项序列组成

    #3


    5  

    While you could have other tags inside (and it might work just fine), you shouldn't because it's not w3c-compliant. It also makes very little semantic sense.

    虽然你可以在里面有其他标签(它可能工作得很好),你不应该因为它不符合w3c。它的语义也很少。

    Just create a simple page and run it throught the validator ( http://validator.w3.org/ ) and you'll see for yourself :)

    只需创建一个简单的页面并通过验证器(http://validator.w3.org/)运行它,你就会看到自己:)

    #4


    2  

    No, this would be invalid markup. However, if you're trying to achieve a different look and feel for some of the lines, you can do this by adding a specific classname to any li tag instead. See below:

    不,这将是无效的标记。但是,如果您尝试为某些行创建不同的外观,则可以通过向任何li标签添加特定的类名来实现此目的。见下文:

    <ul>
        <li class="foobar">Label</li>
        <li>Some text here</li>
        <li>Some text here</li>
        <li class="foobar">Label</li>
        <li>Some text here</li>
        <li>Some text here</li>
    </ul>
    

    #5


    2  

    You can use template tag and it is totally legal. For example:

    您可以使用模板标签,这是完全合法的。例如:

    <ul>
    **<template>**Some text here or <p>Some text here<p> etc**</template>**
    <li>item 1</li>
    **<template>**Some text here or <p>Some text here<p> etc**</template>**
    <li>item 1</li>
    </ul>
    

    #6


    0  

    No. If it's list, it has list-items in it. I can't see any use for list with non-list-items in it; it's not list...

    不。如果是列表,则其中包含列表项。我看不到包含非列表项的列表的任何用途;这不是清单......

    #7


    0  

    You can write such mark up but you shouldn't as it is non-compliant and you may get strange and unexpected results in different browsers.

    你可以写这样的标记,但你不应该因为它不符合标准而且你可能会在不同的浏览器中得到奇怪和意想不到的结果。

    #8


    0  

    if your doing this to style a part of the list-element, you could do this

    如果你这样做来设置list-element的一部分,你可以这样做

    <ul>
      <li>normal text <span>bold text</span></li>
      <li>normal text <span>bold text</span></li>
    </ul>
    

    and then use the CSS

    然后使用CSS

    ul li {font-size: 12px; font-weight: normal;}
    ul li span {font-size: 12px; font-weight: bold;}
    

    hope this helps

    希望这可以帮助

    #9


    0  

    Knockout.js specific answer, you can use the following comment syntax.

    Knockout.js具体答案,您可以使用以下注释语法。

    <ul>
        <li class="header">Header item</li>
        <!-- ko foreach: myItems -->
            <li>Item <span data-bind="text: $data"></span></li>
        <!-- /ko -->
    </ul>
    
    <script type="text/javascript">
        ko.applyBindings({
            myItems: [ 'A', 'B', 'C' ]
        });
    </script>
    

    #1


    44  

    For your code to be valid you can't put any tag inside a <ul> other than an <li>.

    为了使您的代码有效,您不能将任何标记放在除

  • 之外的
      中。

  • 之外的中。
  • You can however, put any block level element inside the <li>, like so:

    但是,您可以将任何块级元素放在

  • 中,如下所示:

  • 中,如下所示:
  • <ul>
            <li>
                <h2>...</h2>
                <p>...</p>
                <p>...</p>
            </li>
    </ul>
    

    #2


    10  

    According to the W3C Recommendation, the basic structure of a list must be:

    根据W3C建议书,列表的基本结构必须是:

    <UL>
       <LI> ... first list item...
       <LI> ... second list item...
       ...
    </UL>
    

    You can put p tags only inside of li tags, not as direct children of ul. The W3C Recommendation expressly states:

    你可以只在li标签内部放置p标签,而不是ul的直接子节点。 W3C建议明确指出:

    lists are made up of sequences of list items defined by the LI element

    列表由LI元素定义的列表项序列组成

    #3


    5  

    While you could have other tags inside (and it might work just fine), you shouldn't because it's not w3c-compliant. It also makes very little semantic sense.

    虽然你可以在里面有其他标签(它可能工作得很好),你不应该因为它不符合w3c。它的语义也很少。

    Just create a simple page and run it throught the validator ( http://validator.w3.org/ ) and you'll see for yourself :)

    只需创建一个简单的页面并通过验证器(http://validator.w3.org/)运行它,你就会看到自己:)

    #4


    2  

    No, this would be invalid markup. However, if you're trying to achieve a different look and feel for some of the lines, you can do this by adding a specific classname to any li tag instead. See below:

    不,这将是无效的标记。但是,如果您尝试为某些行创建不同的外观,则可以通过向任何li标签添加特定的类名来实现此目的。见下文:

    <ul>
        <li class="foobar">Label</li>
        <li>Some text here</li>
        <li>Some text here</li>
        <li class="foobar">Label</li>
        <li>Some text here</li>
        <li>Some text here</li>
    </ul>
    

    #5


    2  

    You can use template tag and it is totally legal. For example:

    您可以使用模板标签,这是完全合法的。例如:

    <ul>
    **<template>**Some text here or <p>Some text here<p> etc**</template>**
    <li>item 1</li>
    **<template>**Some text here or <p>Some text here<p> etc**</template>**
    <li>item 1</li>
    </ul>
    

    #6


    0  

    No. If it's list, it has list-items in it. I can't see any use for list with non-list-items in it; it's not list...

    不。如果是列表,则其中包含列表项。我看不到包含非列表项的列表的任何用途;这不是清单......

    #7


    0  

    You can write such mark up but you shouldn't as it is non-compliant and you may get strange and unexpected results in different browsers.

    你可以写这样的标记,但你不应该因为它不符合标准而且你可能会在不同的浏览器中得到奇怪和意想不到的结果。

    #8


    0  

    if your doing this to style a part of the list-element, you could do this

    如果你这样做来设置list-element的一部分,你可以这样做

    <ul>
      <li>normal text <span>bold text</span></li>
      <li>normal text <span>bold text</span></li>
    </ul>
    

    and then use the CSS

    然后使用CSS

    ul li {font-size: 12px; font-weight: normal;}
    ul li span {font-size: 12px; font-weight: bold;}
    

    hope this helps

    希望这可以帮助

    #9


    0  

    Knockout.js specific answer, you can use the following comment syntax.

    Knockout.js具体答案,您可以使用以下注释语法。

    <ul>
        <li class="header">Header item</li>
        <!-- ko foreach: myItems -->
            <li>Item <span data-bind="text: $data"></span></li>
        <!-- /ko -->
    </ul>
    
    <script type="text/javascript">
        ko.applyBindings({
            myItems: [ 'A', 'B', 'C' ]
        });
    </script>