当前位置:网站首页>响应式——媒体查询
响应式——媒体查询
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>
边栏推荐
- Mysql 45讲学习笔记(六)全局锁
- MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
- MySQL 45 lecture learning notes (x) force index
- 颈椎、脚气
- tars源码分析之6
- Can the out of sequence message complete TCP three handshakes
- 17-18. Dependency scope and life cycle plug-ins
- Is the insurance annuity product worth buying? Is there a hole?
- tars源码分析之1
- 运算符<< >>傻瓜式测试用例
猜你喜欢
Uniapp custom environment variables
Another company raised the price of SAIC Roewe new energy products from March 1
[March 3, 2019] MAC starts redis
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
[backpack DP] backpack problem
R statistical mapping - random forest classification analysis and species abundance difference test combination diagram
uniapp 自定义环境变量
selenium IDE插件下载安装使用教程
24 magicaccessorimpl can access the debugging of all methods
Abap:ooalv realizes the function of adding, deleting, modifying and checking
随机推荐
List of top ten professional skills required for data science work
tars源码分析之10
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
MySQL 45 lecture learning notes (x) force index
Distributed cap theory
7. Agency mode
uniapp 自定义环境变量
tars源码分析之8
The sorting in C language realizes the number sorting method from small to large
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Tar source code analysis 6
测试用例的设计
1、 Relevant theories and tools of network security penetration testing
Another company raised the price of SAIC Roewe new energy products from March 1
What is the sheji principle?
Appium基础 — APPium安装(二)
Fast power (template)
Fundamentals of SQL database operation
Software keywords and process information intercepted by Golden Shield video player
Modify TCP timestamp to optimize transmission performance