HTML列表标签 - 如何从其他颜色中提供每种不同的颜色?

时间:2022-10-10 12:03:47

how to give each <li> different color from other on Html

如何在Html上给每个

  • 不同的颜色

  • <ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
    <ul>
    

    so, Iam looking to Display Items as the Following:

    所以,我希望显示项目如下:

    Item 1 In red color

    项目1红色

    item 2 In blue color

    第2项蓝色

    item 3 In green color

    第3项绿色

    What is the best way to do it ?

    最好的方法是什么?

    2 个解决方案

    #1


    Create different classes like this in css

    在css中创建这样的不同类

       .redText
        {
            color:red;
        }
        .blueText
        {
            color:blue;
        }
        .greenText
        {
            color:green;
        }
    

    And then in your html

    然后在你的HTML中

    <ul>
    <li class = "redText">Item 1</li>
    <li class = "blueText" >Item 2</li>
    <li class = "greenText">Item 3</li>
    <ul>
    <ul>
    

    JSFIDDLE DEMO

    #2


    Try style component for each list.

    尝试每个列表的样式组件。

    <ul>
    <li style="color:red">Item 1</li>
    <li style="color:blue">Item 2</li>
    <li style="color:green">Item 3</li>
    </ul>
    

    #1


    Create different classes like this in css

    在css中创建这样的不同类

       .redText
        {
            color:red;
        }
        .blueText
        {
            color:blue;
        }
        .greenText
        {
            color:green;
        }
    

    And then in your html

    然后在你的HTML中

    <ul>
    <li class = "redText">Item 1</li>
    <li class = "blueText" >Item 2</li>
    <li class = "greenText">Item 3</li>
    <ul>
    <ul>
    

    JSFIDDLE DEMO

    #2


    Try style component for each list.

    尝试每个列表的样式组件。

    <ul>
    <li style="color:red">Item 1</li>
    <li style="color:blue">Item 2</li>
    <li style="color:green">Item 3</li>
    </ul>