当屏幕小于设定像素时

CSS

@media screen and (max-width: 768px){
	small.showinfo {
		display: none;
	}
}

参数:@media screen and (max-width: 768px) {}

当屏幕像素小于 768px 时,响应 small.showinfo {} 样式;

当屏幕大于和小于设定像素区间时

CSS

@media only screen and (min-width: 767px) and (max-width: 1024px) {
	.appFlex {
	    display: flex;
	    flex-wrap: wrap;
	    flex-direction: row;
	    align-content: stretch;
	    justify-content: space-between;
	}
}

参数:@media screen and (max-width: 768px) {}
改为:@media only screen and (min-width: 767px) and (max-width: 1024px) {}

当屏幕像素在 767px 至 1024px 区间时,响应 .appFlex {} 样式;

当屏幕大于设定像素时

CSS

@media screen and (min-width: 769px) {
	select.DashSelecter {
	    width: 100%;
	    height: 50px;
	    font-size: 14px;
	    color: #7f7f7f;
	    outline: none;
	    border: 1px solid #9e9e9e66;
	    border-radius: 3px;
	    padding: 10px;
	    margin: 5px 0 8px 0;
	}

	input.DashInput {
		width: 100%;
		display: initial;
	}
}

参数:@media screen and (min-width: 769px) {}

当屏幕像素大于 769px 时,响应 select.DashSelecter {} 样式;

  • max-width: 为小于设定值
  • min-width: 为大于设定值

更多通用参考模板

指定屏幕尺寸大小区间范围

CSS

@media only screen and (min-width: 310px) and (max-width: 360px) {
	.mediaScope {
		display:none;
	}
}
@media only screen and (min-width: 360px) and (max-width: 374px) {
	.mediaScope {
		display:none;
	}
}

@media only screen and (min-width: 375px) and (max-width: 400px) {
	.mediaScope {
		display:none;
	}
}

@media only screen and (min-width: 400px) and (max-width: 767px) {
	.mediaScope {
		display:none;
	}
}

@media only screen and (min-width: 767px) and (max-width: 1024px) {
	.mediaScope {
		display:none;
	}
}

指定屏幕的最大或最小界定值

CSS

body {
	background-color: #0EAD69;
}

@media screen and (max-width:1600px) {
	body {
		background-color: #3BCEAC;
	}
}

@media screen and (max-width:1280px) {
	body {
		background-color: #FFD23F;
	}
}

@media screen and (max-width:960px) {
	body {
		background-color: #EE4266;
	}
}

@media screen and (max-width:600px) {
	body {
		background-color: #540D6E;
	}
}

CSS

body {
	background-color: #0EAD69;
}

@media screen and (max-width:1600px) {
	body {
		background-color: #3BCEAC;
	}

}

@media screen and (max-width:1280px) {
	body {
		background-color: #FFD23F;
	}

}

@media screen and (max-width:960px) {
	body {
		background-color: #EE4266;
	}
}

@media screen and (max-width:600px) {
	body {
		background-color: #540D6E;
	}
}

切换屏幕方向(横竖屏)的自适应

CSS

@media screen and (orientation:portrait) {
	body {
		background-color: #ffd23f;
	}
}

@media screen and (orientation:landscape) {
	body {
		background-color: #ee4266;
	}
}

根据界面变化自动响应样式

CSS

.example {
    padding: 20px;
    color: white;
}

/* 超小设备 (手机, 600px 以下屏幕设备) */
@media only screen and (max-width: 600px) {
    .example {
    	background: red;
    }
}

/* 小设备 (平板电脑和大型手机,600 像素及以上) */
@media only screen and (min-width: 600px) {
    .example {
    	background: green;
    }
}

/* 中型设备(平板电脑,768 像素及以上)*/
@media only screen and (min-width: 768px) {
    .example {
    	background: blue;
    }
} 

/* 大型设备(笔记本电脑/台式机,992 像素及以上)*/
@media only screen and (min-width: 992px) {
    .example {
    	background: orange;
    }
} 

/* 超大型设备(大型笔记本电脑和台式机,1200 像素及以上)*/
@media only screen and (min-width: 1200px) {
    .example {
    	background: pink;
    }
}

HTML

<p class="example"> 请手动改变窗口的宽度尺寸来查看变化效果。</p>

https://static.hexingxing.cn/v2/example/css@media.query.width.adaptive.html

根据适配分辨率显示或隐藏元素

CSS

@media(max-width:768px) {
	.overflow-maxview {
		display: none!important
	}
}

@media(min-width:769px) {
	.overflow-minview {
		display: none!important
	}
}

HTML

<span class="overflow-maxview">content</span>
<span class="overflow-minview">content</span>

了解更多

https://www.w3cplus.com/css/css-media-queries-guide.html


友情提示:本站所有文章,如无特殊说明或标注,均为何星星原创发布。与此同时,趋于近年来本站的文章内容频繁被他站盗用与机器采集,现已全局禁用网站文字内容操作,了解详情或转载文章请 点此 继续!
分类: 前端开发

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注