简体   繁体   English

css-div除了单个属性外都一样

[英]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.

相关问题 jQuery - 为 class 的所有 div 更改 css,“this”除外 - jQuery - Change css for all divs of a class except 'this' CSS 按钮对齐除最后一个之外的所有 div - CSS buttons align for all divs except the last one 除了将鼠标悬停在div上之外,如何定位同一类别的所有div? - How to target all divs of the same class except for hovered over div? 如何将2个相对div放在彼此/ top css属性上不同的浏览器,css所以它们在所有浏览器中显示相同? - How to position 2 relative divs over each other/top css property differs across browsers, with css so they appear the same in all browsers? 如何简单地 CSS class 除了一个属性外具有相同的属性 - How to simply CSS class with same properties except one property 除一个属性外,所有在Sencha Touch 2中工作的CSS列表 - All CSS working in Sencha Touch 2 list except for one property 如何删除除一个元素以外的所有元素,并保持相同的CSS路径? - How to remove all elements except for one, maintaing the same CSS path to it? 如何保持 CSS Gallery 中的 div 保持一致,或所有大小相同或两者兼而有之? - How to Keep divs in CSS Gallery in Line, or All The Same Size or Both? 使用CSS将一行div设置为相同的高度 - Making a row of divs all be the same height using CSS drupal,OM Maximenu用相同的css类包装所有内容div - drupal, OM Maximenu wraps all content divs with same css class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM