7种方法解决 移动端 1px边框
https://blog.csdn.net/z591102/article/details/106404049
https://www.codenong.com/cs106143210/
https://blog.csdn.net/duanhy_love/article/details/123568732
transform 实现1px边框
伪类+transform是比较完美的方法,原理
- 把原先元素的 border 去掉,然后利用 :before 或者 :after 重做 border ,
- 并 transform 的 scale 缩小一半,原先的元素相对定位,新做的 border 绝对定位
border1px
scss, mixin,支持定义函数,传入变量
.border1px($color:) {
position: relative;
&:after {
content: '';
position: absolute;
left: 0;
bottom: 0;
width: 100%;
border-top: 1px solid $color;
transform: scaleY(0.5);
}
}
.border-none() {
&:after
display: none;
}
.bg-image($url) {
background-image: url($url + "@2x.png");
@media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3) {
background-image: url($url + "@3x.png")
}
}
border1px less
// mixin
.foo(@bg: #f5f5f5, @color: #999){
background: @bg;
color: @color;
}
// 移动端 1px边框
.border1px(@color: rgba(7,17,27, .1)) {
position: relative;
&:after {
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)
.border-1px
&::after
-webkit-transform: scaleY(0.7)
transform: scaleY(0.7)
@media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2)
.border-1px
&::after
-webkit-transform: scaleY(0.5)
transform: scaleY(0.5)
.clearfix
display: inline-block
&:after
display: block
content: "."
height: 0
line-height: 0
clear: both
visibility: hidden
// 使用
.tab {
.foo();
.border1px(#f00);
}
mixin参考 https://www.jianshu.com/p/6a1dedde2316
bg-image 3x icon
https://blog.csdn.net/hzxOnlineOk/article/details/103562629
https://blog.csdn.net/sinat_33184880/article/details/105290142
.bg-image(@url) {
display: inline-block;
margin-right: 4px;
background-image: ~"url(./icon/@{url}@2x.png)";
background-repeat: no-repeat;
font-style:normal; // 清除斜体
vertical-align: middle;
@media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {
background-image: ~"url(./icon/@{url}@3x.png)";
}
}
.bulletinTitle {
vertical-align: -2px;
width: 22px;
height: 12px;
margin-right: 4px;
.bg-image('user');
background-size: 22px 12px;
}
@import
引入 less全局变量
@import '~@/assets/less/@mixin.less';
@mixin的常用方法
https://blog.csdn.net/Tokki_/article/details/94441903