scss 常用的函数总结。
/***
* px2rem 转换
*/
$base-font-size: 750;
@function px2rem($px) {
@return $px / 75px * 1rem;
}
@function rem($px) {
@return ($px / $base-font-size) * 10rem;
}
@function vw($px) {
@return ($px / $base-font-size) * 100vw;
}
/*
* methods
*/
// 定位上下左右居中
@mixin pcenter {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
// 定位上下居中
@mixin ptcenter {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
// 定位左右居中
@mixin plcenter {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
// 字体大小,颜色
@mixin fsc($size, $color) {
font-size: px2rem($size);
color: $color;
}
// flex 布局和子元素对齐方式
@mixin flex($type: space-between) {
display: flex;
justify-content: $type;
}
@mixin wh($width, $height) {
width: $width;
height: $height;
}
@mixin square($size) {
@include wh($size, $size);
}
@mixin size($width, $height) {
width: $width;
height: $height;
}
@mixin text_overflow($lines: 1) {
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: $lines;
-moz-line-clamp: $lines;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
@if $lines == 1 {
white-space: nowrap;
display: block;
} @else {
display: -webkit-box;
}
}
@mixin overflow-line($lines) {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
/*! autoprefixer: ignore next */
-webkit-box-orient: vertical;
-webkit-line-clamp: $lines;
-moz-line-clamp: $lines;
}
@mixin text-overflow($lines: 1) {
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: $lines;
-moz-line-clamp: $lines;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
@if $lines == 1 {
white-space: nowrap;
display: block;
} @else {
display: -webkit-box;
}
}
@mixin overflow_auto {
overflow: auto;
-webkit-overflow-scrolling: touch;
}
@mixin box-sizing($sizing: border-box) {
-webkit-box-sizing: $sizing;
-moz-box-sizing: $sizing;
box-sizing: $sizing;
}
@mixin sc($size, $color) {
font-size: $size;
color: $color;
}
@mixin clearfix {
&:before,
&:after {
content: ' ';
display: table;
}
&:after {
clear: both;
}
}
@mixin iphoneX-footer() {
[data-dpr='2'] & {
@media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) {
//iphoneXR
padding-bottom: calc(env(safe-area-inset-bottom) * 2);
}
}
[data-dpr='3'] & {
@media only screen and (-webkit-device-pixel-ratio: 3) {
//iphone X Xs XsMax
padding-bottom: calc(env(safe-area-inset-bottom) * 3);
}
}
}
相信坚持的力量,日复一日的习惯.
分类:
html css
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2019-09-27 layer实现鼠标悬浮效果