【问题标题】:Can i nest to one off two parents with LESS我可以用LESS与两个父母中的一个嵌套吗
【发布时间】:2013-04-17 15:41:57
【问题描述】:

我有这个 LESS 设置。我想知道,是否可以为两个父母之一筑巢?

 input[type="text"].text_field,
 textarea.text_field {
    // style for both

    textarea + & {
      // style for only text area
    }
  }

我需要为textarea 添加一些其他样式,我不想让它超出主要规则。那么,这可能吗?

【问题讨论】:

    标签: css input nested textarea less


    【解决方案1】:

    如果你想让它们保持相同的规则,你可以尝试这样的事情:

    .text_field {
      color: black;
    
      input& {
        padding: 5px;
      }
    
      textarea& {
        padding: 5px;
      }
    }
    

    【讨论】:

    • 好的,我建议在任何地方检查这个解决方案,但是当我这样做时,这个巢不起作用......
    • 好的,我知道为什么,那是因为我在 body 标签中有这个规则,有没有任何选项可以忽略 body 标签?
    • 我不知道。您嵌套在body标签内的任何原因?嵌套 IMO 似乎有点深。您可能可以使其更通用并将其移到 body 标记之外。
    【解决方案2】:
     input[type="text"].text_field, textarea.text_field {
        // style for both
        font-size: 15px;
        padding: 2px 5px;
     }
     textarea.text_field {
        // style for only text area, you can use !important if you want to use different style, and you used it in input[type="text"].text_field, textarea.text_field
        font-size: 13px !impotrant;
     }
    

    嵌套示例:

     ul {
       // style
       li {
         // style
         a:link, a:hover, a:visited {
           // style: color, font-size, etc.
         }
         a:hover {
           text-decoration: underline;
         }
       }
     }
    

    【讨论】:

    • 看来这个答案不符合“不......超出主要规则”的资格,因为您已将textarea 排除在主要规则之外(这显然是一个解决方案,但不符合 OP 设置的标准)。
    • 对不起,但这显然是解决方案,与我的问题无关
    猜你喜欢
    • 2019-05-20
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多