我正在阅读“CSS the Definitive Guide”第 3 版的第 10 章,图 10-55 中有一个我无法重现的代码示例,我不知道出了什么问题。
特别是书中的代码说
p {border: 1px solid; background: #DDD; margin: 0;}
b {background: #808080;}
em {background: #BBB;}
#one {position: absolute; top: 0; left: 0; width: 50%; height: 10em; z-index: 10;}
#two {position: absolute; top: 5em; left: 25%; width: 50%; height: 10em; z-index: 7;}
#three {position: absolute; top: 11em; left: 0; width: 50%; height: 10em; z-index: 1;}
#one b {position: absolute; right: -3em; top: auto; z-index: 36;}
#two em {position: absolute; bottom: -0.75em; left: 7em; right: -2em; z-index: -42;}
#three b {position: absolute; left: 3em; top: 3.5em; width: 25em; z-index:23;}
图 10-55 如下所示:
jsfiddle:http: //jsfiddle.net/dunsondog109/WvJxR/
然而,
<html>
<head>
<style>
p {
border: 1px solid;
background: #DDD;
margin: 0;
}
b {
background: #808080;
}
em {
background: #BBB;
}
#one {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 10em;
z-index: 10;
}
#two {
position: absolute;
top: 5em;
left: 25%;
width: 50%;
height: 10em;
z-index: 7;
}
#three {
position: absolute;
top: 11em;
left: 0;
width: 50%;
height: 10em;
z-index: 1;
}
#one b {
position: absolute;
right: -5em;
top: 4em;
width: 20em;
z-index: -404;
}
#two b {
position: absolute;
right: -3em;
top: auto;
z-index: 36;
}
#two em {
position absolute;
bottom: -0.75em;
left: 7em;
right: -2em;
z-index: -42;
}
#three b {
position: absolute;
left: 3em;
top: 3.5em;
width: 25em;
z-index: 23;
}
</style>
</head>
<body>
<p id="one">
This element contains normal text with in the browser. There is also some <em>[one]emphasized</em> text to place, or not, depending on the element in question. This element is ID'd "one," if that helps.<b>[one] a boldfaced element big enough to see</b>
</p>
<p id="two">
This element contains normal text with in the browser. There is also some <em>[one]emphasized</em> text to place, or not, depending on the element in question. This element is ID'd "two," if that helps.<b>[two] a boldfaced element big enough to see</b>
</p>
<p id="three">
This element contains normal text with in the browser. There is also some <em>[one]emphasized</em> text to place, or not, depending on the element in question. This element is ID'd "three," if that helps.<b>[three] a boldfaced element big enough to see</b>
</p>
</body>
</html>
生产
我的问题是:
为什么当 z-index 较低时,粗体元素会显示在其父元素的前面?此外,如何更正我的代码以使其看起来像书中的图片?