响应式布局@media screen and ( max-width: 像素值 ) {}

时间:2021-09-16
本文章向大家介绍响应式布局@media screen and ( max-width: 像素值 ) {},主要包括响应式布局@media screen and ( max-width: 像素值 ) {}使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

设计思路很简单,首先先定义在标准浏览器下的固定宽度(假如标准浏览器的分辨率为1024px,那么我们设置宽为980px),然后用Media Query来监测浏览器的尺寸变化,当浏览器的分辨率小于1024px的时候,则通过Media Query预设的样式表来将页面的宽度设置为百分比显示,这样子页面的结构元素就会根据浏览器的的尺寸来进行相对应的调整。同理,当浏览器的可视区域改变到某个值(假如为650px)的时候,页面的结构元素根据Media Query预设的层叠样式表来进行相对应的调整。看看我们的例子:

/*在CSS里添加如下示例代码*/

/* 当浏览器的可视区域小于980px */
@media screen and ( max-width: 980px ) {
#wrap {width: 90%; margin:0 auto;}
#content {width: 60%;padding: 5%;}
#sidebar {width: 30%;}
#footer {padding: 8% 5%;margin-bottom: 10px;}
}
/* 当浏览器的可视区域小于650px */
@media screen and ( max-width: 650px ) {
#header {height: auto;}
#searchform {position: absolute;top: 5px;right: 0;}
#content {width: auto; float: none; margin: 20px 0;}
#sidebar {width: 100%; float: none; margin: 0;}
}

/*显示的表格部份也可以这样定义*/
table{margin:0 auto;font-size:12px;width:98%;}
table{border-left:1px solid #a2c6d3;border-top:3px solid #0180CF;}
table td{border-right:1px solid #a2c6d3;border-bottom:1px solid #a2c6d3;}
table td{padding:2px 4px;word-wrap:break-word;word-break:break-all;min-width:88px;}
.tt{background:#e5f2fa;line-height:18px;font-weight:bold;FONT-SIZE:12px;max-width:596px;}
table.ss{border:1px solid #000;border-spacing:inherit;border-collapse:collapse;}
.ss td{border:1px solid #000;border-spacing:inherit;border-collapse:collapse;}
/* 当浏览器的可视区域小于650px */
@media screen and (max-width: 650px) {
table{border:0;border-top:0px solid #0180CF;}
table thead {display:none;}
table tr{margin-bottom:18px;display:block;border-top:2px solid #0180CF;}
table tr{border-bottom:1px solid #0180CF;}
table td {display:block;text-align:left;font-size:12px;}
table td {border-left:1px dotted #0180CF;border-bottom: 1px dotted #ccc;}
table td:last-child {border-bottom:0;}
table td:before {content:attr(data-label);float:left;text-transform:uppercase;}
table td:before {font-weight:bold;color:red;margin:0px 6px;}
}

原文地址:https://www.cnblogs.com/appinz/p/15292778.html