English 中文(简体)
DIVs 的扎布拉式剪辑
原标题:Zebra-like css styling for nested DIVs

我把DIV要素nes开,对此我不了解nes。 我需要各自具有与其父母不同的背景,从而形成一种类似于黄色的颜色。 我只利用两个背景——黑暗和白色。 其影响必须类似于杂草,甚至儿童在集装箱内,但在我的情况下,儿童被nes。 我可以这样做,就每个要素制定规则,例如:

div  div  div  div {
    background-color: #fff;
}

div  div  div {
    background-color: #aaa;
}

div  div {
    background-color: #fff;
}

div {
    background-color: #aaa;
}

But I m looking for more elegant solution. Can this be done only with CSS? Do I need javascript?

任何建议都将受到高度赞赏。

Edit: I am looking for a solution which will not require the elements to have a class, since they will need to be rearranged with drag & drop (javascript)

问题回答

UPDATE:鉴于这个问题的最新情况,这一解决办法已不再适用。 引自<>。

我只使用“偶然”和“奇”类(或同等的):

div.even {
    background-color: #fff;
}

div.odd {
    background-color: #aaa;
}

之后,用超文本:

<div class="even">
    <div class="odd">
       <div class="even">
           <div class="odd">
               ...
           </div>
       </div>
    </div>
</div>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!