当前位置:网站首页>响应式——媒体查询
响应式——媒体查询
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>
边栏推荐
- Which water in the environment needs water quality monitoring
- tars源码分析之10
- Option (024) - do all objects have prototypes?
- 运算符<< >>傻瓜式测试用例
- Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
- Appium基础 — APPium安装(二)
- Another company raised the price of SAIC Roewe new energy products from March 1
- Tar source code analysis Part 3
- 微信小程序使用rich-text中图片宽度超出问题
- Google Chrome Portable Google Chrome browser portable version official website download method
猜你喜欢
[March 3, 2019] MAC starts redis
selenium IDE插件下载安装使用教程
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
Google Chrome Portable Google Chrome browser portable version official website download method
Mysql 45讲学习笔记(七)行锁
Overview of convolutional neural network structure optimization
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
Abap:ooalv realizes the function of adding, deleting, modifying and checking
centos8安装mysql.7 无法开机启动
MySQL installation and configuration
随机推荐
Reading notes of Clickhouse principle analysis and Application Practice (4)
Bicolor case
MySQL 45 lecture learning notes (VII) line lock
Is the insurance annuity product worth buying? Is there a hole?
Overview of convolutional neural network structure optimization
MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
C语言中的排序,实现从小到大的数字排序法
Another company raised the price of SAIC Roewe new energy products from March 1
thread priority
Dimension and format of data
Download address of the official website of national economic industry classification gb/t 4754-2017
金盾视频播放器拦截的软件关键词和进程信息
[number theory] fast power (Euler power)
Abap:ooalv realizes the function of adding, deleting, modifying and checking
Arcpy 利用updatelayer函数改变图层的符号系统
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
SQL join, left join, right join usage
图的底部问题
Learning multi-level structural information for small organ segmentation
Mysql 45讲学习笔记(六)全局锁