常用CSS
2022年9月29日大约 3 分钟
常用CSS
/* css reset */
abbr,address,article,aside,audio,b,blockquote,body,canvas,caption,cite,code,dd,del,details,dfn,div,dl,dt,em,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,p,pre,q,samp,section,small,span,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,ul,var,video{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:0 0}
body{line-height:1}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}
nav ul{list-style:none}
blockquote,q{quotes:none}
blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}
a{margin:0;padding:0;font-size:100%;vertical-align:baseline;background:0 0}
/* change colours to suit your needs */
ins{background-color:#ff9;color:#000;text-decoration:none}
mark{background-color:#ff9;color:#000;font-style:italic;font-weight:700}
del{text-decoration:line-through}
abbr[title],dfn[title]{border-bottom:1px dotted;cursor:help}
table{border-collapse:collapse;border-spacing:0}
hr{display:block;height:1px;border:0;border-top:1px solid #ccc;margin:1em 0;padding:0}
input,select{vertical-align:middle}
/* 移动端图片 宽高自适应 */
.img-box{
padding-top: 100%;
position: relative;
overflow: hidden;
}
.img{
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
width: 100%;
}
/*滚动条*/
::-webkit-scrollbar {
/*血槽宽度*/
width: 8px;
height: 8px;
}
::-webkit-scrollbar-thumb {
/*拖动条*/
background-color: #49AEEA;
border-radius: 4px;
}
::-webkit-scrollbar-track {
/*背景槽*/
background-color: #ddd;
border-radius: 4px;
}
/*去掉表单背景色*/
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px white inset !important;
}
/* 工具类 */
.fl {
float: left
}
.fr {
float: right
}
.al {
text-align: left
}
.ac {
text-align: center
}
.ar {
text-align: right
}
.hide {
display: none
}
/* 清除浮动 */
.clearfix:after,
.clearfix:before {
content: "";
display: table;
clear: both;
}
.clearfix {
zoom: 1;
}
/* 使用css样式,扩大可点击区域: */
.large{
position: relative;
}
.large:before{
content: '';
position: absolute;
top: -20rpx;
bottom: -20rpx;
left: -20rpx;
right: -20rpx;
}
/* ----文本行数限制----- */
/* 单行 */
.line-1 {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
/* 多行 */
.line-2 {
-webkit-line-clamp: 2;
}
.line-3 {
-webkit-line-clamp: 3;
}
.line-4 {
-webkit-line-clamp: 4;
}
.line-5 {
-webkit-line-clamp: 5;
}
/*flex布局 父级元素加overflow: hidden*/
.line-2, .line-3, .line-4, .line-5 {
min-width: 0;
overflow: hidden;
word-break: break-all;
text-overflow: ellipsis;
display: -webkit-box; /* 弹性伸缩盒 */
-webkit-box-orient: vertical; /* 设置伸缩盒子元素排列方式*/
}
/* ----文本行数限制----- */
.cursor{
cursor: pointer;
}
/********** fle布局 *********/
.flex,
.flex-row,
.flex-column {
display: flex;
}
/* 水平方向*/
.flex-row {
flex-direction: row;
}
/* 垂直方向 */
.flex-column {
flex-direction: column;
}
/* 水平方向换行 */
.flex-row-wrap {
flex-wrap: wrap;
}
/* 水平方向不换行 */
.flex-nowrap {
flex-wrap: nowrap;
}
/* 水平方向,起点在右端 */
.flex-row-reverse {
flex-direction: row-reverse;
}
.flex-row>* {
display: block;
}
.flex-col {
/* flex: 1; */
flex: 1 1 0%;
}
.flex-center {
align-items: center;
justify-content: center;
}
.flex-middle {
align-items: center;
}
.flex-justify-center {
justify-content: center;
}
.flex-bottom {
align-items: flex-end;
}
.flex-justify-start {
justify-content: flex-start;
}
.flex-justify-end {
justify-content: flex-end;
}
.flex-justify-space-between {
justify-content: space-between;
}
.flex-justify-space-around {
justify-content: space-around;
}
.flex-align-start {
align-content: flex-start;
}
.flex-align-end {
align-content: flex-end;
}
.flex-align-around {
align-content: space-around;
}
.flex-align-between {
align-content: space-between;
}
.flex-col-auto {
flex: 0 auto;
}
/********** fle布局 *********/
SCSS类
// 定义字体
@for $i from 9 through 40 {
.font-#{$i} {
font-size: $i + px;
}
}
// 定义内外边距,历遍1-60
@for $i from 0 through 60 {
// 只要双数和能被5除尽的数
@if $i % 2 == 0 or $i % 5 == 0 {
// 得出:margin-30或者m-30
// .margin-#{$i}, .m-#{$i} {
// margin: $i + px!important;
// }
// 得出:padding-30或者p-30
// .padding-#{$i}, .p-#{$i} {
// padding: $i + px!important;
// }
@each $short, $long in l left, t top, r right, b bottom {
// 缩写版,结果如: m-l-30
// 定义外边距
.m-#{$short}-#{$i} {
margin-#{$long}: $i + px!important;
}
// 定义内边距
.p-#{$short}-#{$i} {
padding-#{$long}: $i + px!important;
}
// 完整版,结果如:margin-left-30
// 定义外边距
// .margin-#{$long}-#{$i} {
// margin-#{$long}: $i + px!important;
// }
// 定义内边距
// .padding-#{$long}-#{$i} {
// padding-#{$long}: $i + px!important;
// }
}
}
}