import 'common.scss'
在需要1px边框的元素样式的开头添加@include px-border(#color,(some_position));。 其中color为边框颜色,some_position中填入需要边框的方位(不填则默认为所有方向),
例如:@include px-border(#000,(top,right));,将会生成上方和右方的黑色边框;@include px-border(#000);,将在四周生成黑色边框。
使用任何你喜欢的构建工具或编辑器插件将.scss产出为.wxss。
common.scss:
- // 1px border
- @mixin px-border($color,$border:all) {
- position: relative;
- &:after {
- content: " ";
- position: absolute;
- top: 0;
- left: 0;
- @if $border == all {
- border: 1px solid $color;
- }
- @else {
- @each $member in $border{
- border-#{$member}: 1px solid $color;
- };
- }
- width: 200%;
- height: 200%;
- -webkit-transform: scale(0.5);
- transform: scale(0.5);
- @media (-webkit-min-device-pixel-ratio:2.5) {
- width: 300%;
- height: 300%;
- -webkit-transform: scale(.33333);
- transform: scale(.33333);
- }
- -webkit-transform-origin: 0 0;
- transform-origin: 0 0;
- box-sizing: border-box;
- }
- }