html - 需要背景图像才能响应
问题描述
我已经设置了背景图片。我需要它来响应。我已经为此使用了媒体查询,但图像是相同的。我应该使用背景大小或宽度和高度来查看它吗?因为它被剪掉了。我尝试了 background-size:100% 100%,但它看起来被拉伸了。
代码如下:
.header-area {
position: fixed;
background: url(images/image.jpg) no-repeat;
background-size:100% 100%;
width: 100%;
height: 100%;
}
.overlay {
position: relative;
z-index: 1;
}
.overlay:after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
background: #000000;
opacity: 0.4;
}
解决方案
制作background-size: cover
和background-position: center
.header-area {
background-image: url("image url");
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
推荐阅读
- google-sheets - 使用 AverageIF 时 Arrayformula 不向下复制
- google-apps-script - 将 textarea HTML 输入中的值插入到一列谷歌表格中
- jenkins - Jenkins获取环境变量形式调用shell脚本
- r - 使用 if else 语句根据四列对数据进行子集化
- java - XmlHttpRequest 请求的资源上不存在“Access-Control-Allow-Origin”标头 - Chrome 浏览器
- c++ - 当我迭代它时,如何获得指向 unordered_map 中键的指针?
- haskell - Rigid / skolem 类型变量:作为参数很好,但使用本地 where/let 语句转义范围
- mysql - Liquibase:如何更新变更日志?
- python - 如何将原始代码转换为函数示例
- c# - CEFSharp 应用程序显示空白屏幕,然后在一分钟后自行响应