gpt4 book ai didi

css - 修复IE8中的定位和生成内容

转载 作者:行者123 更新时间:2023-11-28 16:45:43 25 4
gpt4 key购买 nike

我正在尝试从多个不同的 HTML 元素中组合出一个固定位置的 header ,但出于定位原因,它们都不能在视口(viewport)顶部提供背景色条。我一直在尝试用生成的内容来弥补差异,这在 Firefox 和 IE9 中都有效,但在 IE8 中却遇到了麻烦。

这是一个例子:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>IE8 Positioning Demo</title>
<style type="text/css">
html {
margin: 0;
padding: 0;
}
html:before {
/* A gray bar across the top of the window */
display: block;
position: fixed;
top: 0;
left: 0;
right: 0;
height: 30px;
background: #cccccc;
content: " ";
}
body {
margin-top: 35px;
}
h1 {
/* Position the h1 on top of the gray bar */
position: fixed;
top: 0;
margin: 0;
font: 16px serif;
}
</style>
</head>

<body>
<h1>Banner text</h1>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula
ac quam viverra nec consectetur ante hendrerit. Donec et mollis
dolor. Praesent et diam eget libero egestas mattis sit amet
vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia
consectetur. Donec ut libero sed arcu vehicula ultricies a non
tortor. Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a
semper sed, adipiscing id dolor. Pellentesque auctor nisi id
magna consequat sagittis. Curabitur dapibus enim sit amet elit
pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero
in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi
quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus
mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem
facilisis semper ac in est.</p>
</body>
</html>

您需要调整窗口大小(或多次复制/粘贴 lorem ipsum)以便页面滚动。 IE8 将 h1 正确地视为 position: fixed,但它似乎将 html:before 视为 absolutestatic

我该如何处理这种不一致?

最佳答案

html:before? Seriously? What on Earth are you trying to accomplish? If you want a bar across the top of the window, put it as the first element in the . Nothing should come before the html element.

也许这就是他问题的根源。试试这个:http://jsfiddle.net/M314/JQaTG/

关于css - 修复IE8中的定位和生成内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12525441/

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