gpt4 book ai didi

html - 响应图像,固定比例。无法让代码工作

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

抱歉,我一直在尝试网络上的大量教程来尝试使此图像具有固定的纵横比响应/缩放,但没有任何效果。

这是一张 900x400 像素的图片,我只是想让它在较小的屏幕等上都可见。

这是代码笔 link

<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>

<div id="aboutsec1">
<div class="parallaxbg">
<div class="parallaxcontainer">
<div class="parallaxcontent">
<h1>header</h1>
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
</div>
</div>
</div>

<section id="aboutsec2">
<div class="parallaxbg"></div>
<div class="parallaxbg2"></div>
</section>

</body>
</html>

CSS

html,body{
width:100%;
height:100%;
margin: 0;
padding: 0;
}

/* Basic Parallax Background */
.parallaxbg {
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
width: 100%;
position: relative;
}

/* Basic Parallax Container */
.parallaxcontainer {
display: table;
table-layout: fixed;
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}

/* Basic Parallax Content */
.parallaxcontent {
max-width: 450px;
display: table-cell;
vertical-align: middle;
padding-left: 10%;
padding-right: 10%;
text-align: center;
}

#aboutsec1{
height: 100%;
}

/* About Page Section 1 */
#aboutsec1 .parallaxbg {
background: none;
background-color: #eeeeee;
text-align: center;
}

/* About Page Section 2 */
#aboutsec2 {
}

#aboutsec2 .parallaxbg2 {
background-color: #000000;
background-image: url('http://s16.postimg.org/k5xrwvp7p/900x400.png');
z-index: 1;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
width: 100%;
background-size: cover;
padding-bottom: 44.444444444444%; /* 400px/900px */
}

最佳答案

别担心,我最终自己弄明白了。这是固定纵横比响应式背景图片的代码,如果其他人需要的话...

<div class="imagecontainer">
<div class="responsiveimage"></div>
</div>

.imagecontainer {
margin: 0px auto;
max-width: 900px; \* For a 900px wide image *\
}

.responsiveimage {
background-image: url('');
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
padding-bottom: 44.444444444444%; /* 400px/900px x 100 (for a 900x400 image) */
}

使用总和将 padding bottom 设置为正确的比例,这意味着图像将始终保持相同的纵横比。

关于html - 响应图像,固定比例。无法让代码工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25362146/

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