【问题标题】:Giving different colors to a p tag为 p 标签赋予不同的颜色
【发布时间】:2014-06-09 20:27:36
【问题描述】:

我正在尝试根据不同的条件定义不同的颜色。 我有以下代码:

<p 
style="@((i == 1) ? ("color:#black;") : ("color:#white;"))" </p>

如何为不同的i's 定义不同的颜色。

例如,如果I==1 则样式为黑色,如果I 为2,则样式为蓝色... 我试过 if then else 但我做不到...

【问题讨论】:

    标签: html styles


    【解决方案1】:

    我认为你想要这样做:

    if(i==1){
     <p style="background-color: #ff0000"> here goes anything you want in black</p>
    }
    else{
     <p style="background-color: #3852D6"> here goes anything you want in blue </p>
    }
    

    如果这不是您想要的,如果您向我们展示您的代码并进行解释,也许我们可以为您提供更好的帮助。 希望对你有帮助!..

    【讨论】:

      【解决方案2】:

      在 CSS3 上你可以使用:

      p:nth-child(2)
      {
          background:#ff0000;
      }
      

      还有更多!

      See W3 documentationsupport

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-24
        • 2013-05-22
        • 2015-04-14
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        • 2021-06-11
        • 1970-01-01
        相关资源
        最近更新 更多