Nested CSS styles?

谁说我不能喝 提交于 2019-12-02 19:29:18

问题


Is something like this possible?

.imgbox:hover{ .ui-resizable-se { /*some style */ } }

Or a conceptual equivalent? Basically, only when an element of a certain class is hovered over, then some element within that class should change some style.


回答1:


You can do this:

.imgbox:hover .ui-resizable-se { /*some style */ }

The same can be generated by LESS or SASS.




回答2:


Sure that would be :

.imgbox:hover .ui-resizable-se { /*some style */ } 



回答3:


No, CSS does not allow nesting. You'd have to write it like this:

.imgbox:hover .ui-resizable-se { /*some style */ }

However, there are various CSS preprocessors available which convert something like this in valid CSS. The most popular ones are LESS and SASS/SCSS.




回答4:


Not with plain CSS but you can with a CSS preprocessor like Sass:

http://sass-lang.com/

table.hl {
  margin: 2em 0;
  td.ln {
    text-align: right;
  }
}

li {
  font: {
    family: serif;
    weight: bold;
    size: 1.2em;
  }
}

Generates:

/* CSS */

table.hl {
  margin: 2em 0;
}
table.hl td.ln {
  text-align: right;
}

li {
  font-family: serif;
  font-weight: bold;
  font-size: 1.2em;
}


来源:https://stackoverflow.com/questions/14797622/nested-css-styles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!