What does & do in css

后端 未结 2 468
无人共我
无人共我 2021-01-28 14:51

I am looking at some legacy code and found something like below in the css file:

.user_modal {
  width: auto;
  height\" auto;
  &.modal,
  &.fade.in
  {         


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

    You're probably experienced with SASS selector. The ampersand & in sass is used to refer to the parent selector. So in your case & will refer to parent selector which is .user_modal

    So &.modal which will be converted to CSS and become .user_modal.modal

    so it'll match:

    <div class='user_modal modal'></div>
    

    the same way for &.fade.in which will match

    <div class='user_modal fade in'></div>
    

    So finally it's just become normal CSS after you've converted it:

    .user_modal.modal , .user_modal.fade.in {
        margin-top:0;
        margin-left:0;
        top:83px;
    }
    
    0 讨论(0)
  • 2021-01-28 15:20

    It looks like Sass or LESS. It's user_modal with those other classes in it that are not children of it. The & is a reference to the element/class above it.

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