较少的CSS,嵌套属性,:hover :: after

时间:2013-05-28 16:02:09

标签: css nested less

是否可以用更少的时间来做到这一点?

a {
    &:after {
        background: red;
    }
    &:hover {
        &:after {
            background: blue;
        }
    }
}

当鼠标悬停在?

上时,我无法改变颜色

3 个答案:

答案 0 :(得分:47)

以下对我来说很好:

a {
    &:after {
        content:'a';
        background: red;
    }
    &:hover {
        &:after {
            background: blue;
        }
    }
}

启用了LESS的编辑器,将其编译为:

a:after {
  content: 'a';
  background: red;
}
a:hover:after {
  background: blue;
}

哪种方法有效。

答案 1 :(得分:0)

  

这对我也很好:-

 a{
    &:after{
        background: red;
        content: "Hover Text"
    }
    &:hover{
        &:after{
            background: yellow;
        }
    }
}
  

然后我的终端将其编译为:-

a:after {
  background: red;
  content: "Hover Text";
}
a:hover:after {
  background: yellow;
}

答案 2 :(得分:-6)

a {

  &:after {

     background: red;

  }

  &:hover,
  &:after {

     background: blue;

  }

}

现在没关系:P