stylus让你用更骚的姿势写css 发表于 2018-10-15 | 分类于 开发效率 认识stylus这货 张鑫旭老师的stylus文档 我这里有一波祖传的mixin, 可以让你写更精简可复用的css代码, 这位少侠请了解一下 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223tac() text-align centernorpt() background-repeat no-repeat// 文本处理txt($width, $height, $size) width $width height $height line-height $height font-size $size tac() // 字体大小fs($size) font-size $size// 文本加粗bold() font-weight bold// 行内块inline() display inline-block// 圆circle($size) width $size height $size border-radius 100%// 小圆点dot($size, $color) display inline-block width $size height $size border-radius 100% background-color $color// 模态对话框modal() z-index 1000 position fixed top 0 right 0 bottom 0 left 0 background-color rgba(0, 0, 0, .6)// 占满宽度full-width($height) width 375px height $height// 头像avatar($size) norpt() width $size height $size background-size $size $size border-radius 100%// 描线stroke-line($width, $y) width $width border 0.5px solid #8A91A4 transform translateY($y)// 左浮动fl($margin-left) float left margin-left $margin-left// 文本行text-line($height, $font-size) inline() height $height line-height $height font-size $font-size// 背景图bg($width, $height, $img) norpt() background-size $width $height background-image url('../../assets/images/' + $img + '@2x.png') @media (-webkit-min-device-pixel-ratio 3), (min-device-pixel-ratio 3) background-image url('../../assets/images/' + $img + '@3x.png')// 带背景图with-bg($width, $height, $img) norpt() width $width height $height background-size $width $height background-image url('../../assets/images/' + $img + '@2x.png') @media (-webkit-min-device-pixel-ratio 3), (min-device-pixel-ratio 3) background-image url('../../assets/images/' + $img + '@3x.png')// 有背景图has-bg($width, $height) norpt() width $width height $height background-size $width $height// 组件背景图bg-img($img) background-image url('../../assets/images/' + $img + '@2x.png') @media (-webkit-min-device-pixel-ratio 3), (min-device-pixel-ratio 3) background-image url('../../assets/images/' + $img + '@3x.png')// app.vue背景图app-bg-img($img) background-image url('./assets/images/' + $img + '@2x.png') @media (-webkit-min-device-pixel-ratio 3), (min-device-pixel-ratio 3) background-image url('./assets/images/' + $img + '@3x.png')// 全屏带背景图with-bg-fs($img) width 375px height 667px background-image url($img) background-size 375px 667px// 绝对定位, left, topab-lt($left, $top) position absolute top $top left $left// 绝对定位, right, topab-rt($right, $top) position absolute top $top right $right// 绝对定位, left, bottomab-lb($left, $bottom) position absolute left $left bottom $bottom// 绝对定位, right, bottomab-rb($right, $bottom) position absolute right $right bottom $bottomab-r($right) position absolute right $right top 50% transform translateY(-50%)// 绝对定位, 上下居中, leftab-l($left) position absolute left $left top 50% transform translateY(-50%)// 绝对定位, 左右居中, topab-center-t($top) position absolute left 50% top $top transform translateX(-50%)// 绝对定位, 上下左右都居中ab-center() position absolute top 50% left 50% transform translate(-50%, -50%)// 不换行no-wrap() text-overflow ellipsis overflow hidden white-space nowrap// 扩展点击区域extend-click() &:before content '' position absolute top -10px left -10px right -10px bottom -10px// 灰阶处理gray($scale) filter grayscale($scale)// 1px边框border-1px($color) position: relative &:after display: block position: absolute left: 0 bottom: 0 width: 100% border-top: 1px solid $color content: ' ' @media (-webkit-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5) -webkit-transform: scaleY(0.7) transform: scaleY(0.7) @media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2) -webkit-transform: scaleY(0.5) transform: scaleY(0.5) @media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3) -webkit-transform: scaleY(0.33) transform: scaleY(0.33)// 占满全屏full-screen() width 100vw height 100vh position relative 用法 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<template> <div class="sub-path-card-root"> <div class="pic" :style="{ backgroundImage: `url(${ imgUrl })` }" > </div> <div class="txt">{{ name }}</div> <jsl-stars class="stars" :score=score /> </div></template><script type="text/ecmascript-6">import JslStars from 'base-components/stars/stars'export default { props: ['img', 'score', 'name', 'imgUrl'], data () { return { data: '' } }, components: { JslStars }}</script><style scoped lang="stylus" rel="stylesheet/stylus">@import "~styles/mixin".sub-path-card-root width 101px margin 0 auto .pic margin 0 auto has-bg(101px, 101px) .bg1 bg-img('bg1') .bg2 bg-img('bg2') .bg3 bg-img('bg3') .txt txt(43px, 22px, 16px) margin 7px auto color #fff .stars margin 9px auto 20px</style> 点击打赏 微信支付 支付宝