Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 继承另一个div的颜色?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 继承另一个div的颜色?

Javascript 继承另一个div的颜色?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一些不同颜色的主题 我希望border div“ItemListHeader”继承另一个div“color1”的颜色,而这个div不是css或js的父级(structure HTML bellow)? 谢谢, #颜色1{ 背景色:rgba(11、114、180、1); } #颜色2{ 背景色:rgba(1,14,18,0); } .ItemListHeader{ 右边框:30px实体(继承); } 使用 或者,正如其他人所提到的,通过给两个对象提供相同的类,有

我有一些不同颜色的主题

我希望border div“ItemListHeader”继承另一个div“color1”的颜色,而这个div不是css或js的父级(structure HTML bellow)? 谢谢,

#颜色1{
背景色:rgba(11、114、180、1);
}
#颜色2{
背景色:rgba(1,14,18,0);
}
.ItemListHeader{
右边框:30px实体(继承);
}

使用

或者,正如其他人所提到的,通过给两个对象提供相同的类,有一些工具,例如,允许您在更高的抽象级别上组合CSS

Less称这些为“混合”

而不是

/* CSS */
#header {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#footer {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}
你可以说

/* LESS */
.rounded_corners {
  -moz-border-radius: 8px;
  -webkit-border-radius: 8px;
  border-radius: 8px;
}

#header {
  .rounded_corners;
}

#footer {
  .rounded_corners;
}

为什么不给颜色一个类名,并将其添加到两个元素中呢?在CSS中,您将color1声明为类,并在div中使用它作为ID。它不会在第一个div中应用颜色also@DanielH因为他想把背景颜色“复制”到边框上