gpt4 book ai didi

html - 如何让我的 css 背景图像随窗口大小缩放?

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

我正在构建我的第一个实时网站,我注意到背景图像并没有随窗口缩小然后调整大小。站点的其余部分可以缩放,但背景图像看起来就像全屏一样。我只能假设这意味着它不会完全可见,而是在较小的设备中被切断。是什么导致这种情况发生,我该如何解决?对此的帮助将不胜感激,谢谢

我刚刚发布了我的 css 的一般部分,非响应部分在整个站点共享,但其余部分在 jsfiddle 中 https://jsfiddle.net/zd00nmce/5/

    html,body{
min-height: 100vh;
}
body{
margin: 0px;
background-image: linear-gradient( 0, rgba(0,0,0,.8) 30%, rgba(0,150,255,.8) 100%), url("images/mainCover.jpg");
background-repeat: no-repeat;
background-size: cover;
}
img{
max-width: 100%;
}
h1,h2,h3{
font-family: arial;
text-align: center;
margin: 20px auto;
}
ul{
list-style: none;
text-align: center;
padding: 0;
}
a:visited,a{
color: black;
}
section{
margin: 5%;
color: white;
}
section > article{
padding: 1em;
background-color: rgba(0,0,0,.5);
border-radius: 15px;
margin: 10px;
}

section h2, section h3{
text-align: center;
}
section h2{
font-size: 1.3em;
text-shadow: 3px 3px 3px rgba(0,0,0,.5);
}
section h3{
font-size: 1.1em;
}
/*nav and header*/
header{
background-color: rgba(255,165,0,.8);
display: flex;
flex-flow: row wrap;
justify-content: center;
border-bottom: 8px solid black;
}

header h1{
text-align: center;
margin: 0;
padding: 15px;
font-size: 1.5em;
text-shadow: 5px 5px 5px rgba(0,0,0,.3);
}
header h1, nav a{
font-weight: 700;
font-family: arial;
}

header nav{
position: fixed;
bottom: 0;
width: 100%;
z-index: 1;
// background-color: rgba(255,165,0,.8);
}
.main-nav{
margin: 0;
width: 100%;
color: white;
font-family: arial;
font-weight: 600;
}
nav ul li{
text-align: center;
border: 1px solid white;
border-radius: 15px;
font-size: 1.2rem;
background-color:rgba(255,165,0,.8);
width: 100%;
}
.drop-menu-back{
display: none;
width: 100%;
}
a{
text-decoration: none;
}

nav a:visited, nav a,h1{
color: white;
}

.main-nav .current-page {
background-color: rgba(0,0,0,.5);
}

/****drop down menu****/
.characters:hover {
position: relative;
border-radius: 8px 8px 0 0;
}

.drop-menu{
position: absolute;
visibility: hidden;
display: block;
top: 38px;
white-space: nowrap;
left: -2px;
background-color: rgba(255,165,0,.8);
border: 1px solid rgba(0,0,0,.02);
box-shadow: 5px 5px 5px 2px rgba(0,0,0,.3);
opacity: 0;
transition: opacity 300ms ease-in-out 0s;
z-index: 1;
}
.characters:hover .drop-menu{
visibility: visible;
opacity:1;
}

最佳答案

CSS Tricks 对此有一个有用的解决方案。

https://css-tricks.com/perfect-full-page-background-image/

html { 
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

我相信这应该是您要找的。

关于html - 如何让我的 css 背景图像随窗口大小缩放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44577677/

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