gpt4 book ai didi

html - 背景图像位置固定的 div 容器

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:01 25 4
gpt4 key购买 nike

我想创建一个这样的页面:Page

我不想将图像作为背景。我想创建一个 div 容器,这个 div 容器有一个背景图像。在这个 div 下应该是另一个 div。如果我将 div 滚动到带有背景图像的 div 下方,则应该越过带有背景图像的 div。我有一些东西,但它是废话。这是我的页面:1

代码如下:

*{
font-family: "Open Sans";
margin: 0px;
padding: 0px;
font-size: 18px;
}
html {
height: 100%;
}
body{
height: 100%;
background-image: url('http://cdn1.editmysite.com/uploads/3/8/9/4/38945355/background-images/748028443.png') !important;
background-repeat: no-repeat !important;
background-position: 50% 0 !important;
background-size: auto !important;
background-color: transparent !important;
background: inherit;
}

nav{
background: url("images/line-header.png") repeat-x scroll center bottom #4A525A;
padding: 15px;
position: fixed;
top: 0px;
width: 100%;
}

nav > ul{
margin: 0px;
padding: 0px;
text-align: center;
}

nav ul > li{
margin-left: 25px;
display: inline-block;
list-style-type: none;
}

nav ul li > a{
display: block;
text-decoration: none;
color: black;
color: #697683;
transition: color 0.5s;
}

nav ul li > a:hover{
color: #FFF;
}

.content{
height: 1000px;
margin-top: 500px;
background-color: orange;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="index.css" >
<!-- Open Sans -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
</head>
<body>

<nav>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 1</a></li>
</ul>
</nav>

<div class="content">
<h1></h1>
</div>

</body>
</html>

最佳答案

只需添加另一个 div 并将 background-attachment 设置为 fixed

.background{
background: url('http://cdn1.editmysite.com/uploads/3/8/9/4/38945355/background-images/748028443.png') no-repeat;
background-attachment: fixed;
background-size: cover;
height: 500px; <------can make 500px instead of using margin-top: 500px on .content
}


.content{
height: 1000px;
background-color: orange;
/*margin-top: 500px;*/ <-------------take out
}

FIDDLE

关于html - 背景图像位置固定的 div 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27733037/

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