css - 如何用 flexbox div 填充背景图像
问题描述
我有一个要完全填充背景图像的 div。不应显示鲑鱼色。如何让此图像“缩放以适应”?我尝试了各种方法,例如 background-size: 100% 100% 和 flexbox。
https://codepen.io/2spacemilk/pen/zYKWLyM
.this-div {
background-color: salmon;
display: flex;
flex-direction: column;
align-items: center;
background-image: url('https://i.imgur.com/6aRX4Hh.png');
background-size: cover;
}
.payment-methods-strip {
background-color: #fff;
max-width: 438px;
border-radius: 40px;
padding: 10px 20px;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
align-items: center;
}
解决方案
问题似乎是您的背景图像顶部有透明空间。因此,图像正在显示,它只是被额外的不可见空间向下推。您可以尝试从图像中删除多余的空间(使用图像编辑器)吗?如果没有,您可以尝试使用background-position
手动将其定位到顶部。
推荐阅读
- docker - 在 docker hub 上扩展多阶段构建镜像的阶段
- javascript - 我想在 ajax 调用加载页面后切换一个 div
- java - 为背景图像编写自动化代码
- python - 图像分析、物体形状、中心和极值
- qlikview - 如何使用 pptxgenjs 库中的 slide.pageNumber() 幻灯片方法
- amazon-web-services - nodejs process.env 变量在 aws lambda 中不起作用
- xml - 如何将 Aramex API 与 WSDL 和 Python 3.6 一起使用?
- java - 解析浮点数在 Java 中不正确地舍入值
- javascript - 每 X 秒刷新一次页面上的数据以获取角度分量
- sql - 如何使用 TIMESTAMP 进行增量加载?