CSS more short query

前端 未结 5 1779
独厮守ぢ
独厮守ぢ 2021-01-26 06:45

For example I have a CSS selector:

#spotlightPlayer .container .commands.over span,
#spotlightPlayer .container .commands.over ul,
#spotlightPlayer .container .c         


        
5条回答
  •  深忆病人
    2021-01-26 07:10

    So what you effectively want is a 'with'/grouping construct?

    I don't think CSS can do this directly, but it's certainly would useful.

    It probably would not be too difficult to write a basic script that generated the long-hand version from the shorthand.

    However, perhaps a more consistent syntax would be:

    @with( #spotlightPlayer .container .commands.over )
    {
        span, ul, ul li { clear:both }
    }
    

    Whilst longer in this case, it would allow you to add more styles that apply only within that specific block.

    edit: or better yet, go with the css pre-processor suggested in the other answer.


    Also, regarding Jeremy's answer/comment: Unless you have (or plan to have) a .commands.over item outside of the .container item, then you can drop the middle part.

    When you space-delimit your selectors, it allows for any descendant, rather than requiring direct parent/child relationship (like > does).

提交回复
热议问题