我可以和LESS的两个父母一起窝

时间:2013-04-17 15:41:57

标签: css input nested textarea less

我设置了这个LESS。我想知道,有没有选择为两个父母中的一个筑巢?

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

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

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

2 个答案:

答案 0 :(得分:7)

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

.text_field {
  color: black;

  input& {
    padding: 5px;
  }

  textarea& {
    padding: 5px;
  }
}

答案 1 :(得分:0)

 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;
     }
   }
 }