屏幕分辨率小于特定尺寸时隐藏DIV元素
时间:2023年03月31日
/来源:网络
/编辑:佚名
当我们网页样式呈现方面有一些特殊需求时,比如PC端网页一个DIV元素的内容在移动端上不想体现,要隐藏掉,那么这时有什么办法?其实解决方案很容易,参考如下步骤:

屏幕分辨率小于特定尺寸时隐藏DIV元素
1、在CSS样式表里添加如下代码:
CSS
@media only screen and (max-width: 1000px) {
#fadeshow {
display: none;
}
}
意思就是当屏幕分辨率小于1000像素时,元素显示:无,也就是整块在网页上不显示,并且不占位。
2、在你需要隐藏的DIV上加上:id="fadeshow",如下示例:
<div id="fadeshow" style="height: 58px; background-color: #000;"></div>
那么这样PC端会显示,而移动端就会隐藏了,当然1000px可以自己定义数值,考虑平板上是否要体现。

屏幕分辨率小于特定尺寸时隐藏DIV元素
1、在CSS样式表里添加如下代码:
CSS
@media only screen and (max-width: 1000px) {
#fadeshow {
display: none;
}
}
意思就是当屏幕分辨率小于1000像素时,元素显示:无,也就是整块在网页上不显示,并且不占位。
2、在你需要隐藏的DIV上加上:id="fadeshow",如下示例:
<div id="fadeshow" style="height: 58px; background-color: #000;"></div>
那么这样PC端会显示,而移动端就会隐藏了,当然1000px可以自己定义数值,考虑平板上是否要体现。
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03