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是比较完美的方法,原理

  1. 把原先元素的 border 去掉,然后利用 :before 或者 :after 重做 border ,
  2. 并 transform 的 scale 缩小一半,原先的元素相对定位,新做的 border 绝对定位

border1px

scss, mixin,支持定义函数,传入变量

  1. .border1px($color:) {
  2. position: relative;
  3. &:after {
  4. content: '';
  5. position: absolute;
  6. left: 0;
  7. bottom: 0;
  8. width: 100%;
  9. border-top: 1px solid $color;
  10. transform: scaleY(0.5);
  11. }
  12. }
  13. .border-none() {
  14. &:after
  15. display: none;
  16. }
  17. .bg-image($url) {
  18. background-image: url($url + "@2x.png");
  19. @media (-webkit-min-device-pixel-ratio: 3),(min-device-pixel-ratio: 3) {
  20. background-image: url($url + "@3x.png")
  21. }
  22. }

border1px less

  1. // mixin
  2. .foo(@bg: #f5f5f5, @color: #999){
  3. background: @bg;
  4. color: @color;
  5. }
  6. // 移动端 1px边框
  7. .border1px(@color: rgba(7,17,27, .1)) {
  8. position: relative;
  9. &:after {
  10. position: absolute;
  11. left: 0;
  12. bottom: 0;
  13. width: 100%;
  14. border-top: 1px solid $color;
  15. content: '';
  16. }
  17. }
  18. @media (-webkit-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5)
  19. .border-1px
  20. &::after
  21. -webkit-transform: scaleY(0.7)
  22. transform: scaleY(0.7)
  23. @media (-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2)
  24. .border-1px
  25. &::after
  26. -webkit-transform: scaleY(0.5)
  27. transform: scaleY(0.5)
  28. .clearfix
  29. display: inline-block
  30. &:after
  31. display: block
  32. content: "."
  33. height: 0
  34. line-height: 0
  35. clear: both
  36. visibility: hidden
  37. // 使用
  38. .tab {
  39. .foo();
  40. .border1px(#f00);
  41. }

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
image.png

  1. .bg-image(@url) {
  2. display: inline-block;
  3. margin-right: 4px;
  4. background-image: ~"url(./icon/@{url}@2x.png)";
  5. background-repeat: no-repeat;
  6. font-style:normal; // 清除斜体
  7. vertical-align: middle;
  8. @media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {
  9. background-image: ~"url(./icon/@{url}@3x.png)";
  10. }
  11. }
  12. .bulletinTitle {
  13. vertical-align: -2px;
  14. width: 22px;
  15. height: 12px;
  16. margin-right: 4px;
  17. .bg-image('user');
  18. background-size: 22px 12px;
  19. }

@import

引入 less全局变量

  1. @import '~@/assets/less/@mixin.less';

@mixin的常用方法
https://blog.csdn.net/Tokki_/article/details/94441903