var使用自定义属性
自定义属性
- 属性名以 – 开头
- 属性值为任何有效的css值
- 只有后代元素可以使用
<!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>
/* 在html中定义全局变量 */
html {
--main-color: #f00;
}
h1 {
color: var(--main-color);
}
</style>
</head>
<body>
<p>123</p>
<h1>h1</h1>
</body>
</html>
页面显示:
calc计算
注意,±运算符两边要有空格
<!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>
.outer {
width: 100%;
height: 200px;
background-color: pink;
}
.outer>.box {
width: calc(100% - 100px);
height: 200px;
background-color: #bfa;
}
</style>
</head>
<body>
<div class="outer">
<div class="box"></div>
</div>
</body>
</html>
blur模糊
<!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>
.img01 {
filter: blur(5px);
}
.box {
position: relative;
}
.box>.cover {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0, 0, 0, .5);
backdrop-filter: blur(5px);
}
</style>
</head>
<body>
<img class="img01" src="../images/0.jpg" alt="">
<div class="box">
<img src="../images/0.jpg" alt="">
<div class="cover"></div>
</div>
</body>
</html>
gradient渐变
gradient系列属于img的子类型
<!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>
div {
width: 200px;
height: 200px;
}
.box1 {
/* background-image: url(); */
background-image: linear-gradient(to top right, red, blue);
}
.box2 {
background-image: radial-gradient(at 0% 50%, red, blue);
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>