html中响应式查询,css 响应式(媒介查询)

本文介绍如何使用CSS媒体查询创建响应式网站布局,通过不同屏幕尺寸下的样式调整,实现从多栏到单栏的自适应变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.CSS 来实现响应式

CSS实现响应式网站的布局要用到的就是CSS中的媒体查询接下来来简单介绍一下:

@media 类型 and (条件1) and (条件二){css样式}

我们只需用到width衍生出的max-width这个属性,定义输出设备中的页面可见区域宽度来控制该改变的样式即可。

html代码如下:

响应式

头部

左部
中部
右部

demo01.css样式如下:

body{

margin:0;

text-align:center;

}

.header{

height:100px;

background-color:red;

}

.container{

height:400px;

background-color:pink;

}

.clearfix:after{

display:block;

content:"";

visibility:hidden;

height:0;

clear:both;

}

.footer{

height:100px;

background-color:blue;

}

.left{

width:20%;

background-color:orange;

float:left;

height:300px;

}

.center{

width:55%;

background-color:gray;

float:left;

height:300px;

margin:0 2.5%;

}

.right{

width:20%;

background-color:yellow;

float:left;

height:300px;

}

demo02的样式如下:

body{

margin:0;

text-align:center;

}

.header{

height:100px;

background-color:red;

}

.container{

height:400px;

background-color:pink;

}

.clearfix:after{

display:block;

content:"";

visibility:hidden;

height:0;

clear:both;

}

.footer{

height:100px;

background-color:blue;

}

.left{

width:30%;

background-color:orange;

float:left;

height:300px;

}

.center{

width:70%;

background-color:gray;

float:left;

height:300px;

}

.right{

width:100%;

background-color:yellow;

height:300px;

}

demo03的样式:

body{

margin:0;

text-align:center;

}

.header{

height:100px;

background-color:red;

}

.container{

background-color:pink;

}

.clearfix:after{

display:block;

content:"";

visibility:hidden;

height:0;

clear:both;

}

.footer{

height:100px;

background-color:blue;

}

.left{

width:100%;

background-color:orange;

height:300px;

}

.center{

width:100%;

background-color:gray;

height:300px;

}

.right{

width:100%;

background-color:yellow;

height:300px;

}

效果图:

bVbebeP?w=1364&h=622

窗口大于1024px时显示的样子

bVbebe3?w=724&h=614

当大于640小于980时,右侧栏在底部

bVbebfF?w=457&h=604

当小于480时,导航栏折叠,body三部分竖直排列显示,若窗口持续缩小,不在发生变化,区域被压缩

效果总图:

bVbebw9?w=1342&h=584

持续更新,欢迎大家!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值