html - 覆盖 html/css 中的图像
问题描述
我有一个网站,对于移动视图,我想要不同的图像,而对于桌面视图,我想要另一个。
对于桌面视图,以下 HTML/CSS 代码运行良好:
HTML:
<div class="et_pb_section et_pb_section_0 demo-request-backgroundimage et_pb_with_background et_section_regular">
</div>
CSS:
div.et_pb_section.et_pb_section_0 {
background-image: url(/wp-content/uploads/2018/05/contactusheader-2-min.jpg)!important;
}
我现在要为移动视图实现什么,我希望调用以下 CSS,但我不确定为什么在移动视图中没有调用以下背景图像。
@media only screen and (max-width: 767px)
{
.demo-request-backgroundimage
{
background-image: url(/wp-content/uploads/2018/05/mobilecontactusheader.jpg) !important;
background-size: cover;
background-repeat: no-repeat;
}
}
解决方案
你想改变.et_pb_section.et_pb_section_0
img 所以在media-query
使用中:
见 jsFiddle:https: https://jsfiddle.net/smuf3c3t/
.et_pb_section.et_pb_section_0 {
background-image: url(https://material.angular.io/assets/img/examples/shiba1.jpg)!important;
width:500px;
height:500px;
}
@media only screen and (max-width: 767px)
{
.et_pb_section.et_pb_section_0
{
background-image: url(https://material.angular.io/assets/img/examples/shiba2.jpg) !important;
background-size: cover;
background-repeat: no-repeat;
}
}
<div class="et_pb_section et_pb_section_0 demo-request-backgroundimage et_pb_with_background et_section_regular">
</div>
所以删除 !IMPORTANT
推荐阅读
- android - 电话不显示反应原生(世博会)上的所有文本
- java - Log Miner 无法捕获数据
- sql - SQL, query to check and list distinct entries that occur in another table within a specific time frame
- flutter - Iterable 具有价值,但是当我尝试将其传递给函数或将其转换为列表时,它似乎为空
- java - 我有一个 ArrayIndexOutOfBoundsException 我不知道为什么
- angular - 多组件双向绑定数据传输
- connection-string - 连接字符串可在 Mac 中使用,但不能直接在 Parallels 中使用
- php - 这是我的取消链接代码,用于从它正在工作的服务器文件夹中删除图像,但它会删除文件夹中的新闻图像
- list - 如何在不同的视图中使用 SwiftUI 中的结构内部的结构?
- php - 如何在另一个文件的另一个类中调用 php 方法?