效果图
上代码
<!DOCTYPE html>
<html lang="zh">
<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>CSS变量</title>
<style>
/* 定义CSS变量 */
html{
/* html 为作用域,定义使用 -- */
--main-color: #C00000;
}
.main{
display: flex;
justify-content: space-around;
align-items: center;
}
.box1,.box2{
border: 1px solid #efefef;
display: flex;
flex-direction: column;
height: 500px;
width: 30%;
justify-content: center;
align-items: center;
}
.box1 div{
width: 100%;
height: 33.33%;
border: 1px solid #efefef;
/* 使用CSS变量 var(变量名) */
background-color: var(--main-color);
}
.box2 div{
width: 100%;
height: 33.33%;
border: 1px solid #efefef;
/* 使用CSS变量 var(变量名) */
color: var(--main-color);
}
</style>
</head>
<body>
<div class="main">
<div class="box1">
<div>box1-1</div>
<div>box1-2</div>
<div>box1-3</div>
</div>
<div class="box2">
<div>box2-1</div>
<div>box2-2</div>
<div>box2-3</div>
</div>
</div>
</body>
</html>
本文来自博客园,作者:depressiom,转载请注明原文链接:https://www.cnblogs.com/depressiom/p/16203879.html