当前位置:网站首页>响应式——媒体查询
响应式——媒体查询
2022-07-04 06:41:00 【HHppGo】
上个bilibili页面出现的问题总结:
元素显示层级:
标准流< 浮动 < 定位
标准流的元素在页面最底部
定位的元素在页面的最上面
注意:header 做了固定定位,在最上层;
之所以出现穿透效果,是因为header没有设置背景色
定位元素的显示层级:
- 定位过的元素显示层级一样
- 但是,HTML写在后面的定位元素的层级高于前面的
- 可以在前面元素的样式中添加
z-index: 1;
使之层级高于后面的(数字只要大于0即可)
媒体查询-基本语法
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> /* 视口宽度小于等于768px, 网页背景色是粉色 */ @media (max-width: 768px) {
body {
background-color: pink; } } /* 视口宽度大于等于1200px, 网页背景色是skyblue */ @media (min-width: 1200px) {
body {
background-color: skyblue; } } </style>
</head>
<body>
</body>
</html>
媒体查询-书写顺序
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> /* 视口宽度 >= 768px,网页背景色是 粉色 视口宽度 >= 992px,网页背景色是 绿色 视口宽度 >= 1200px,网页背景色是 skyblue */ /* 提示: 代码规范 mid-width: 从小到大写 max-width: 从大到小写 */ /* 代码不规范,女朋友两行泪~~(需要改Bug,没时间陪) */ @media (min-width: 768px) {
body {
background-color: pink; } } @media (min-width: 992px) {
body {
background-color: green; } } @media (min-width: 1200px) {
body {
background-color: skyblue; } } </style>
</head>
<body>
</body>
</html>
媒体查询-link引入
one.css是关于>=992px的样式
two.css是关于>=1200px的样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 视口宽度 >= 992px,网页背景色为粉色 one.css-->
<link rel="stylesheet" href="./one.css" media="(min-width:992px)">
<!-- 视口宽度 >= 1200px,网页背景色为绿色 two.css-->
<link rel="stylesheet" href="./two.css" media="(min-width:1200px)">
</head>
<body>
</body>
</html>
媒体查询-隐藏
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style> * {
margin: 0; padding: 0; } .box {
/* 1.flex布局 */ display: flex; width: 100%; } .left {
width: 300px; min-height: 500px; background-color: pink; } .main {
/* 2.弹性伸缩比: 保证left具有300px的宽度 */ flex: 1; min-height: 500px; background-color: skyblue; } /* 3. 视口宽度 <= 992px,隐藏 .left */ @media (max-width:992px) {
.left {
display: none; } } /* visibility: hidden; 隐藏元素:占位隐藏(隐藏的元素还占据位置) display:none; 隐藏元素:不占位隐藏(常用的) */ </style>
</head>
<body>
<div class="box">
<div class="left">left</div>
<div class="main">
响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果响应式网页效果
</div>
</div>
</body>
</html>
边栏推荐
- 采用中微BATG135实现IIC数据/指令交互
- 雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
- C realize Snake games
- Abap:ooalv realizes the function of adding, deleting, modifying and checking
- MySQL installation and configuration
- 同一个job有两个source就报其中一个数据库找不到,有大佬回答下吗
- Selection (023) - what are the three stages of event propagation?
- 1、 Relevant theories and tools of network security penetration testing
- [Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
- 2022 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers
猜你喜欢
SQL join, left join, right join usage
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
P26-P34 third_ template
Overview of convolutional neural network structure optimization
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
期末周,我裂开
centos8安装mysql.7 无法开机启动
MySQL learning notes 3 - JDBC
Fundamentals of SQL database operation
随机推荐
Operator < <> > fool test case
8. Factory method
图的底部问题
C realize Snake games
Overview of convolutional neural network structure optimization
Displaying currency in Indian numbering format
tars源码分析之10
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
2022, peut - être la meilleure année économique de la prochaine décennie, avez - vous obtenu votre diplôme en 2022? Comment est - ce prévu après la remise des diplômes?
How to implement cross domain requests
How does the recv of TCP socket receive messages of specified length?
ABCD four sequential execution methods, extended application
centos8安装mysql.7 无法开机启动
Shopping malls, storerooms, flat display, user-defined maps can also be played like this!
Redis interview question set
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
C réaliser des jeux de serpents gourmands
Reading notes of Clickhouse principle analysis and Application Practice (4)
How to use multithreading to export excel under massive data? Source code attached!