gpt4 book ai didi

html - 即使在指定位置后 Z-index 也不起作用

转载 作者:可可西里 更新时间:2023-11-01 13:06:28 25 4
gpt4 key购买 nike

我遇到了一个问题: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 与段落重叠..

请帮忙。

最佳答案

看这个fiddle

您必须将您的位置更改为relative。也就是说,p 的新 CSS 如下所示

p{
position:relative;
z-index:20;
background-color:white;
}

关于html - 即使在指定位置后 Z-index 也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32464114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com