这篇文章分享给大家的内容是关于css实现响应式布局的方法,内容很有参考价值,希望可以帮到有需要的小伙伴。
用CSS实现响应式布局
响应式布局感觉很高大上,很难,但实际上只用CSS也能实现响应式布局
要用的就是CSS中的没接查询,下面就介绍一下怎么运用:
使用@media 的三种方法
1.直接在CSS文件中使用:
@media 类型 and (条件1) and (条件二){ css样式}@media screen and (max-width:1024px) { body{ background-color: red; }}
登录后复制
2.使用@import导入
@import url(“css/moxie.css”) all and (max-width:980px);
3.也是最常用的方法–直接使用link连接,media属性用于设置查询方法
下面是一个简单的响应式的布局HTMl代码:
立即学习“前端免费学习笔记(深入)”;
响应式 头部
左边
中间
右边
登录后复制
下面是CSS样式:
*{ margin:0; padding:0; text-align:center; color:yellow; }.header{ width:100%; height:100px; background:#ccc; line-height:100px;}.main{ background:green; width:100%;}.clearfix:after{ display:block; height:0; content:""; visibility:hidden; clear:both;}.left,.center,.right{ float:left;}.left{ width:20%; background:#112993; height:300px; font-size:50px; line-height:300px;}.center{ width:60%; background:#ff0; height:400px; color:#fff; font-size:50px; line-height:400px;}.right{ width:20%; background:#f0f; height:300px; font-size:50px; line-height:300px;}.footer{ width:100%; height:50px; background:#000; line-height:50px;}
登录后复制
样式代码
.right{ float:none; width:100%; background:#f0f; clear:both;}.left{ width:30%;}.center{ width:70%;}.main{ height:800px;}
登录后复制
样式代码
.left,.center,.right{ float:none; width:100%;}
登录后复制
当窗口大于1024px 时,指挥被压缩,并不会发生其他变化:
当窗口小于1024px,大于720px的时候,右侧栏取消浮动,在下边显示:
当窗口小于720px的时候,左中右三栏,全都取消浮动,宽度100%:
好了,布局就这么简单,细节的把握还靠不断地练习。
相关推荐:
关于CSS更改鼠标为手状样式的介绍
关于CSS更改鼠标为手状样式的介绍
以上就是CSS实现响应式布局的方法的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2894848.html