[英]css - divs all the same except single property
Is there any kind of inheritance in css? CSS中有任何继承吗?
For example, divA, divB, divC all existing in the same spot with all the same properties, only differing by their z-index? 例如,divA,divB,divC都存在于同一位置且具有相同的属性,只是z-index不同?
The idea being using jquery or whatnot to have different transitions between the sections. 使用jquery或诸如此类的想法在各节之间具有不同的过渡。
Is anything like this possible or am I going about this the wrong way? 这样的事情有可能发生吗,或者我会以错误的方式处理吗?
Is there any kind of inheritance in css?
CSS中有任何继承吗?
Yes. 是。 Most properties can be given the value
inherit
which means "The same value for this property as the parent node has". 可以为大多数属性提供值
inherit
,这意味着“该属性与父节点具有相同的值”。 This isn't the type of inheritance you are thinking of though. 这不是您正在考虑的继承类型。
For example, divA, divB, divC all existing in the same spot with all the same properties, only differing by their z-index?
例如,divA,divB,divC都存在于同一位置且具有相同的属性,只是z-index不同?
CSS has no way to say that one rule-set should copy values from another one. CSS没有办法说一个规则集应该从另一个规则集复制值。 You can do:
你可以做:
#divA, #divB, #divC /* Or another selector that matches all the elements */
{ /* Common rules */ }
#divA { /* specific rules */ }
/* etc */
or various other strategies including generating your CSS using a script and using multiple classes on a single element. 或其他各种策略,包括使用脚本生成CSS并在单个元素上使用多个类。
You can specify multiple classes for a single element, eg 您可以为单个元素指定多个类,例如
<div class="divA divB">
So with that you can do some clever trickery to get what you want. 这样一来,您就可以做一些巧妙的骗术来获得想要的东西。
CSS does have inheritance, that is one of the main principles of CSS. CSS确实具有继承性,这是CSS的主要原理之一。
jQuery can handle pretty much any scenario you want. jQuery几乎可以处理您想要的任何情况。 If you provide a more detailed code writeup we can help more.
如果您提供更详细的代码编写,我们可以提供更多帮助。
HTML: HTML:
<div id="container">
<div id="divA">A</div>
<div id="divB">B</div>
<div id="divC">C</div>
</div>
CSS 的CSS
#container div
{
/*all your common styles here */
}
#divA { /*div specific style here */ }
#divB { /*div specific style here */ }
#divC { /*div specific style here */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.