我只能通过添加额外的标记来做到这一点。需要添加一个空的div,实质上它起着父背景的作用。看看这里的CSS。
HTML部分:
<div class="parent">
Parent
<div class="child">
Child
<div class="grandson">
Grandson
<div class="grandson-bg"></div>
</div>
<div class="child-bg"></div>
</div>
<div class="parent-bg"></div>
</div>
CSS部分:
article, aside, figure, footer, header, hgroup, menu, nav, section { display: block; }
.parent { display: block; position: relative; z-index: 0;
height: auto; width: auto; padding: 25px;
}
.parent-bg { display: block; height: 100%; width: 100%;
position: absolute; top: 0px; left: 0px;
border: 1px solid white; z-index: 0;
}
.parent-bg:hover { border: 1px solid red; }
.child { display: block; position: relative; z-index: 1;
height: auto; width: auto; padding: 25px;
}
.child-bg { display: block; height: 100%; width: 100%;
position: absolute; top: 0px; left: 0px;
border: 1px solid white; z-index: 0;
}
.child-bg:hover { border: 1px solid red; }
.grandson { display: block; position: relative; z-index: 2;
height: auto; width: auto; padding: 25px;
}
.grandson-bg { display: block; height: 100%; width: 100%;
position: absolute; top: 0px; left: 0px;
border: 1px solid white; z-index: 0;
}
.grandson-bg:hover { border: 1px solid red; }
http://jsbin.com/ubiyo3/edit
感谢您试用:)不过你,因为这可扩展性韩元”的为我工作。 – 2010-04-23 19:41:42
哈哈哈谢谢,这是一个有趣的问题要解决。我以前完全遇到过这个完全相同的问题,但我认为我的解决方案是手动更改没有悬停声明的父级的类。这对你来说不起作用,因为你想让你的父母继续工作。我的程序员认为我会因为这个丑陋,丑陋的黑客而被严重低估。谢谢你证明他错了;) – 2010-04-23 21:58:14