Can a CSS selector reference another selectors property?

后端 未结 2 648
野趣味
野趣味 2021-01-18 01:06

I\'ve just noticed that Webkit now has some support regarding the CSS Values and Units Module Level spec. And I was wondering if anyone knows if there is a way to reference

相关标签:
2条回答
  • 2021-01-18 01:19

    Other than using a pre-compiler such as sass/scss or less, I believe all you can do is wait or hard-code it.

    0 讨论(0)
  • 2021-01-18 01:28

    I added an answer to the question you linked: https://stackoverflow.com/a/11071806/137626

    • You can use the same declaration block with as many selectors as you want by grouping them (selectors are separated by commas)
    • You can't reuse the same declaration block later with a different CSS selector without rewriting the whole declaration block preceded by this selector or using a preprocessor/macro that'll do that for you. Or add it to the existing declaration block as above

    Now with your example of an element resized by CSS itself: you could use CSS3 Media Queries and its @media rules containing as many declaration blocks as you want. These media queries would adapt to the width of viewport here.
    Mixing expanding elements via animation and media queries that would've the reverse effect will be very soon very complicated (and I'll wonder what content you're playing with); if you want to Keep It Simple, then JS is the way to go. There are variables, loops, events ;) and you can start a CSS3 animation by adding or removing a single class from an element (or whatever CSS selector).
    CSS3 won't replace JS (and you shouldn't use JS to style HTML as JS isn't activated or existing everywhere and there's already a nice fallback named CSS).

    0 讨论(0)
提交回复
热议问题