我遇到了一个问题: HTML:
<!DOCTYPE html>
<html>
<head>
<title>Forming Layouts</title>
<meta http-equiv="author" content="@infinity">
<link rel="stylesheet" type="text/css" href="E:\HTML STUFF\css.css">
</head>
<body>
<h1>The Evolution of the Bicycle</h1>
<p id="top">In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster: two same-size in-line wheels, the front one steerable, mounted in a frame upon which you straddled. The device was propelled by pushing your feet against the ground, thus rolling yourself and the device forward in a sort of gliding walk.</p>
<p>The machine became known as the Draisienne (or "hobby horse"). It was made entirely of wood. This enjoyed a short lived popularity as a fad, not being practical for transportation in any other place than a well maintained pathway such as in a park or garden.</p>
<p>The next appearance of a two-wheeled riding machine was in 1865, when pedals were applied directly to the front wheel. This machine was known as the velocipede (meaning "fast foot") as well as the "bone shaker," since it's wooden structure combined with the cobblestone roads of the day made for an extremely uncomfortable ride. They also became a fad and indoor riding academies, similar to roller rinks, could be found in large cities.</p>
<p>In 1870 the first all-metal machine appeared. (Prior to this, metallurgy was not advanced enough to provide metal which was strong enough to make small, light parts out of.) The pedals were attached directly to the front wheel with no freewheeling mechanism. Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
<p>The front wheels became larger and larger as makers realized that the larger the wheel, the farther you could travel with one rotation of the pedals. For that reason, you would purchase a wheel as large as your leg length would allow. This machine was the first one to be called a bicycle ("two wheel"). These bicycles enjoyed a great popularity during the 1880s among young men of means. (They cost an average worker six month's pay.)</p>
<p>Because the rider sat so high above the center of gravity, if the front wheel was stopped by a stone or rut in the road, or the sudden emergence of a dog, the entire apparatus rotated forward on its front axle and the rider, with his legs trapped under the handlebars, was dropped unceremoniously on his head. Thus the term "taking a header" came into being.</p>
</body>
</html>
CSS:
h1{
position:fixed;
top:0;
left:0;
right:0;
background-color:cyan;
margin:0px;
z-index:10;
color:white;
}
#top{
margin-top:100px;
}
p{
position:static;
z-index:20;
background-color:white;
}
现在,当我向下滚动时,段落应该超过标题。但它不是那样的。即使所有段落的z-index为20且h1为10,h1与段落重叠..
请帮助。
答案 0 :(得分:3)
您必须将position
更改为relative
。也就是说,p
的新CSS将如下所示
p{
position:relative;
z-index:20;
background-color:white;
}