CSS-Less class extend class with pseudo class

后端 未结 2 534
长情又很酷
长情又很酷 2020-12-15 19:44

I was wondering how I could do something like the following with less css:

.btn {
  color : black;
}

.btn:hover {
  color : white;
}

.btn-foo {
  .btn;
  &         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 20:14

    UPDATE: If you can't modify external files just redefine the selectors, and add missing states:

    .btn {
      // not adding anything here, won't affect existing style
      &:hover {
        // adding my own hover state for .btn
        background: yellow;
        ...
      }
    }
    
    // this will make your foo button appear as in external style
    // and have the :hover state just as you defined it above
    .btn-foo {
      .btn;
    }
    

    Better now? :)


    You don't need pseudo class. It will just work :)

    Try this:

    .btn {
      background: yellow;
    
      &:hover { // define hover state here
        background: green;
      }
    }
    
    button {
      .btn;
    }
    

    Each

提交回复
热议问题