【发布时间】:2020-05-19 16:32:23
【问题描述】:
我在调整 flexbox 中的背景图像大小时遇到了问题。 想要做的是背景图像在调整浏览器窗口大小时水平缩小,而不是垂直缩小。 我尝试了不同的背景大小属性,并尝试了最大和最小高度/宽度以及 flex-shrink,但对我没有任何作用。 提前致谢!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.image-header {
display: flex;
min-height: 75vh;
background-image: linear-gradient(rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.25)),
url('https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/190403-pancakes-066-copy-1554497284.jpeg?crop=0.777xw:0.584xh;0.115xw,0.315xh&resize=1200:*');
background-repeat: no-repeat;
background-attachment: fixed;
max-width: 100%;
background-size: contain;
position: relative;
}
.image-header h1 {
color: white;
padding: 25px;
text-shadow: 2px 2px 2px black;
position: absolute;
bottom: 0;
left: 0;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="main-image">
<div class="image-header">
<h1>Easy Fluffy American Pancakes</h1>
</div>
</body>
</html>
【问题讨论】:
-
background-size;auto 100%应该可以工作但是它需要一个非常大的图像,因为它需要足够宽以覆盖整个屏幕宽度, -
不幸的是,它不起作用。基本上,我想获得与本网站相同的效果:hairybikers.com/recipes/view/beef-goulash 在调整大小时图像不会在其下方留下这个空白区域。