这种组件化模块化的思想是非常重要的。这使得维护代码变得简单。
card卡片组件
代码
card.less
.card{
border:solid 1px #ddd;//边框
box-shadow: 0 0 5px rgb(128, 125, 125);//边上的阴影
border-radius: .2rem;
.card-header{
padding:1rem;
border:solid 1px #ddd;//这里的同样颜色可以设置成一个变量,方便更改
}
.card-body{
padding:1rem;
}
.card-footer{
padding:1rem;
border-top:solid 1px #ddd;
}
}
title.less
:
h2,h3,h4{
color:#555;
}
h2{
font-size:1rem;
}
h3{
font-size:.8rem;
}
<div class="card">
<div class="card-header">
<h3>newest</h3>
</div>
<div class="card-body"></div>
<div class="card-footer"></div>
</div>
效果
list-group组件
代码
list-group:
.list-group{
li{
display:flex;
justify-content:space-between;//两侧对齐
padding: .8rem 0;//上下内边距 左右不要
border-bottom:solid 1px #ddd;
font-size:.8rem;
&:last-child{//最后一个不想要底线
border-bottom:none;
}
a{
color:#777;
}
span{
font-size: .5rem;
color:#888;
}
}
}
HTML:
<div class="container">
<div class="row">
<div class="col-6 col-lg-9 col-sx-12">
<div class="card">
<div class="card-header">
<h3>newest</h3>
</div>
<div class="card-body">
<ul class="list-group">
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
</ul>
</div>
<div class="card-footer">footer</div>
</div>
</div>
<div class="col-6 col-lg-3 col-sx-12">
<div class="card">
<div class="card-header">
<h3><i class="fa fa-home" aria-hidden="true"></i>社区</h3>
</div>
</div>
</div>
</div>
</div>
效果
页码组件
代码
page.less:
.page{
display:flex;
a{
display:block;
padding:.3rem .8rem;
border:solid 1px #ddd;
margin-left: -1px;
color:#555;
&:first-child{
border-top-left-radius: .3rem;
border-bottom-left-radius: .3rem;
}
&:last-child{
border-top-right-radius: .3rem;
border-top-right-radius: .3rem;
}
&.current{
background-color:rgb(21, 156, 73);
color:rgba(255, 255, 255, 0.993);
border:solid 1px rgb(21, 156, 73);
}
}
}
html:
<div class="card-footer">
<div class="page">
<a href=""><i class="fa fa-angle-double-left" aria-hidden="true"></i></a>
<a href="">1</a>
<a href="">2</a>
<a href="" class="current">3</a>
<a href="">4</a>
<a href="">5</a>
<a href=""><i class="fa fa-angle-double-right" aria-hidden="true"></i></a>
</div>
</div>
效果
边距控制组件
代码
margin:
.mb-1{
margin-bottom: 1rem;
}
.mb-2{
margin-bottom: 2rem;
}
.mb-3{
margin-bottom: 3rem;
}
.mb-4{
margin-bottom: 4rem;
}
.mb-5{
margin-bottom: 5rem;
}
HTML:
<body>
<header class="mb-1">//其实关键就在第一行 看懂这里就好了 下面的都不用看
<div class="container ">
<div class="navbar">
<a href="#" class="logo">okkjoo</a>
<label for="toggle-nav">
<i class="fa fa-tasks" aria-hidden="true"></i>
</label>
<input type="checkbox" id="toggle-nav">
<div class="collapse">
<ul class="links">
<li><a href="">在线文档</a></li>
<li><a href="">讨论平台</a></li>
<li><a href="">关于本人</a></li>
<li><a href="">keepgoing</a></li>
</ul>
<div class="form">
<a href="">登录</a>
<a href="" class="form-bg">注册</a>
</div>
</div>
</div>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-6 col-lg-9 col-sx-12">
<div class="card">
<div class="card-header">
<h3>newest</h3>
</div>
<div class="card-body">
<ul class="list-group">
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
<li>
<a href="#">test1</a>
<span>2021-05-27</span>
</li>
</ul>
</div>
<div class="card-footer">
<div class="page">
<a href=""><i class="fa fa-angle-double-left" aria-hidden="true"></i></a>
<a href="">1</a>
<a href="">2</a>
<a href="" class="current">3</a>
<a href="">4</a>
<a href="">5</a>
<a href=""><i class="fa fa-angle-double-right" aria-hidden="true"></i></a>
</div>
</div>
</div>
</div>
<div class="col-6 col-lg-3 col-sx-12">
<div class="card">
<div class="card-header">
<h3><i class="fa fa-home" aria-hidden="true"></i>社区</h3>
</div>
</div>
</div>
</div>
</div>
</body>
效果
REM单位操作尺寸响应处理
关于REM
在common.less
中给:root
的字体设置过了15px
(:root
可以理解为HTML
),那么此时 1rem
就是15px
此时如果你想在别的尺寸调整字体大小,例如:你想调整小尺寸时字体大小。
可以直接在small.less
中设置一个:root
👇覆盖掉common.less
中的即可。
代码
:root{
font-size:20px;
}