当前位置:网站首页>响应式——媒体查询
响应式——媒体查询
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>
边栏推荐
- Manually page the list (parameter list, current page, page size)
- Cervical vertebra, beriberi
- ABCD four sequential execution methods, extended application
- R statistical mapping - random forest classification analysis and species abundance difference test combination diagram
- Summary of leetcode BFS question brushing
- Tar source code analysis Part 2
- MySQL 45 lecture learning notes (XIV) count (*)
- Tsinghua University product: penalty gradient norm improves generalization of deep learning model
- 抽奖系统测试报告
- Tar source code analysis 6
猜你喜欢

InputStream/OutputStream(文件的输入输出)

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 Xinjiang's latest eight members (Safety Officer) simulated examination questions and answers

selenium IDE插件下载安装使用教程

Learn about the Internet of things protocol WiFi ZigBee Bluetooth, etc. --- WiFi and WiFi protocols start from WiFi. What do we need to know about WiFi protocol itself?

Sleep quality today 78 points

Arcpy 利用updatelayer函数改变图层的符号系统

How to use multithreading to export excel under massive data? Source code attached!

centos8安装mysql.7 无法开机启动

Uniapp custom environment variables
随机推荐
Tar source code analysis Part 7
Option (024) - do all objects have prototypes?
[March 3, 2019] MAC starts redis
17-18. Dependency scope and life cycle plug-ins
Code rant: from hard coding to configurable, rule engine, low code DSL complexity clock
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
Can the out of sequence message complete TCP three handshakes
How does the recv of TCP socket receive messages of specified length?
R statistical mapping - random forest classification analysis and species abundance difference test combination diagram
InputStream/OutputStream(文件的输入输出)
How to use multithreading to export excel under massive data? Source code attached!
Tar source code analysis Part 2
7. Agency mode
Analysis of tars source code 5
Mysql 45讲学习笔记(十二)MySQL会“抖”一下
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?
Download kicad on Alibaba cloud image station
Arcpy uses the updatelayer function to change the symbol system of the layer
Sort list tool class, which can sort strings
MySQL 45 lecture learning notes (VII) line lock