手机自适应设计代码以及案例
手机自适应设计的三大根本:
一:允许网页自动调整宽度
<meta name="viewport" content="width=device-width, initial-scale=1" />
说明:viewport是网页默认的宽度和高度,上面这行代码的意思是,网页宽度默认等于屏幕宽度(width=device-width),原始缩放比例(initial-scale=1)为1.0,即网页初始大小占屏幕面积的100%
二:不使用绝对宽度
CSS代码不能指定像素宽度: width:xxx px; 只能指定百分比宽度: width: xx%;或者:width:auto;
三:使用相对大小的字体
body { font: normal 100% Helvetica, Arial, sans-serif; }
上面的代码指定,字体大小是页面默认大小的100%
手机自适应实现的方法:
一:使用百分比
把标签的宽度设置为百分比的样式,如
img{width:100%;}
二、不同尺寸的屏幕调用不同的css样式
<link rel="stylesheet" type="text/css" href="style1.css" media="screen and (max-width: 600px)">
<link rel="stylesheet" type="text/css" href="style2.css" media="screen and (min-width: 600px) and (max-width: 800px)">
三、使用css实现,根据屏幕宽度设置css样式
@media screen and (min-width:371px) and (max-width:380px) {.float_container .title_talk {font-size: 18px; background-size: 32px}.float_container dd {width: 84%;margin-top: 12px;}.float_container .box {font-size: 11px;margin-top: 1px;}.float_container .btn_cf a {border-radius: 10px;font-size: 15px}.float_container dt img{ margin-top: 36px;}.cf{margin-top: -14px;}
}
@media screen and (min-width:381px) and (max-width:412px) {.float_container .title_talk {font-size: 18px; background-size: 32px}.float_container dd {width: 84%;margin-top: 12px;}.float_container .box {font-size: 11px;margin-top: 1px;}.float_container .btn_cf a {border-radius: 10px;font-size: 15px}.float_container dt img{ margin-top: 36px;}.cf{margin-top: -14px;}
}
@media screen and (min-width:413px) and (max-width:414px) {.float_container .title_talk {font-size: 18px; background-size: 32px}.float_container dd {width: 84%;margin: -8px;}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
