【发布时间】:2014-06-20 14:53:54
【问题描述】:
我遇到了一个问题,我无法获得使某些代码工作所需的特异性水平。我有一个<ul>,我想为它制作<li> 的背景,当它悬停在一个漂亮的小滑入式动画上时。
我设法在:hover 上使用linear-gradient 和transition 让它工作得很好。我决定让不同的列表项有不同的背景颜色,所以我添加了三个类:.red、.blue 和.gold,我想我会用@987654329 制作所有内容@class 具有线性渐变本身以外的必需属性,即background-size: 200% 100%、background-position:right bottom 和transition:all 1s ease,然后为每个单独的颜色类指定线性渐变和颜色。我知道这一切都是无形的,但我会在下面发布我的代码。
这是我希望拥有的东西(或类似的东西):
body .push [class^="level1"] {
background-size: 200% 100%;
background-position:right bottom;
transition:all 1s ease;
}
body .push [class^="level1"]:hover {
background-position:left bottom;
}
body .push .level1.blue {
background: linear-gradient(to right, #282e59 50%, rgba(0,0,0,0) 50%);
}
body .push .level1.red {
background: linear-gradient(to right, #94272a 50%, rgba(0,0,0,0) 50%);
}
body .push .level1.gold {
background: linear-gradient(to right, #e5d037 50%, rgba(0,0,0,0) 50%);
}
但这不起作用。为了使第一个类中的值生效,我必须摆脱第一个 body .push [class^="level1"] { ... } 并将该信息放入三个特定颜色的值中,例如
body .push .level1.blue {
background: linear-gradient(to right, #282e59 50%, rgba(0,0,0,0) 50%);
background-size: 200% 100%;
background-position:right bottom;
transition:all 1s ease;
}
body .push .level1.red {
background: linear-gradient(to right, #94272a 50%, rgba(0,0,0,0) 50%);
background-size: 200% 100%;
background-position:right bottom;
transition:all 1s ease;
}
body .push .level1.gold {
background: linear-gradient(to right, #e5d037 50%, rgba(0,0,0,0) 50%);
background-size: 200% 100%;
background-position:right bottom;
transition:all 1s ease;
}
有没有办法整合这些信息?
【问题讨论】:
-
您是否使用
body来获得特异性?如果没有,那么您应该能够在所有 css 规则中丢弃它。 -
好点。我不确定我在想什么,谢谢。
标签: css css-specificity memory-efficient