自适应布局
2016-04-18 21:27
351 查看
原文链接:https://www.geek-share.com/detail/2671986022.html
关于自适应布局,主要是在不同的设备中,显示都能达到一种理想的效果,所以采用了自适应。
<!DOCTYPE html> <html> <head> <title>layout.html</title> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <link href="layout.css" type="text/css" rel="stylesheet" media='only screen and (max-width:640px)'/>//这句话的意思是说如果设备的宽度在640px以下的话就遵循这个样式 <style> @media screen and (min-width:640px){ body{ background-color:blue; } } </style> </head> <body> This is my HTML page. <br> </body> </html>
对应的css文件
*{ margin:0; padding:0px; background-color:red; }
自适应的小案例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width = device-width,initial-scale=1">//这句话是设置自适应布局的标示语 <link href="1.css" type="text/css" rel="stylesheet"/> </head> <body> <div class="header"></div> <div class="container"> <div class="left"></div> <div class="main"></div> <div class="right"></div> </div> <div class="footer"></div> </body> </html>
css文件
*{ margin:0; padding:0; } @media screen and (min-width: 940px){ .header, .container, .footer{ margin:10px auto; width:940px; height:450px; } .header{ background-color:red; } .container{ } .footer{ background-color:yellow; } .left,.main,.right{ float:left; width:300px; height:450px; background-color:blue; } .main{ margin-left:20px; margin-right:20px; } } @media screen and (min-width: 600px) and (max-width:940px){ .header, .container, .footer{ margin:10px auto; width:600px; height:450px; } .header{ background-color:red; } .container{ } .footer{ background-color:yellow; } .left,.main{ float:left; width:290px; height:450px; background-color:blue; } .right{ display:none; } .main{ margin-left:20px; } } @media screen and (max-width: 600px) { .header, .footer{ height:450px; } .container{ margin:10px auto; width:400px; height:1400px; } .header{ background-color:red; } .container{ } .footer{ background-color:yellow; } .left,.main,.right{ margin:0 auto; width:300px; height:450px; background-color:blue; } .main{ margin-bottom:10px; margin-top:10px; } }
转载于:https://www.cnblogs.com/yuaima/p/5405950.html
相关文章推荐
- div + css宽度自适应(液态布局)
- css布局之左侧固定右侧自适应布局
- 高度100%的绝对定位自适应布局
- 自适应布局百分比和定值的计算方案
- 典型的三行二列居中高度自适应布局
- css判断不同分辨率显示不同宽度布局实现自适应宽度
- 静态、自适应、流式、响应式四中布局的区别
- 如何使用CSS网格创建一个自适应布局
- Android自适应屏幕大小和layout布局(横屏|竖屏)
- css二列布局(左边固定,右边自适应)
- Android_自适应布局
- 二列宽度自适应布局
- 前端:实现一个三栏布局,两边固定,中间自适应
- Css三列自适应布局
- (div+css)上面固定下面自适应页面布局的实现(FF,IE)
- Android自适应屏幕大小和layout布局(横屏|竖屏)
- 高度100%的绝对定位自适应布局
- H5+JS+相对单位rem实现第三方支付页(输入金额+模拟数字键盘+自适应布局+大写金额)
- 网页布局自适应和JS设置IMG属性
- 自适应布局下的图片垂直水平居中,自适应手机横竖屏