android上实现0.5px线条

Bertha 。 2023-01-03 04:15 225阅读 0赞

由于安卓手机无法识别border: 0.5px,因此我们要用0.5px的话必须要借助css3中的-webkit-transform:scale缩放来实现。

原理:将伪元素的宽设为200%,height设为1px通过-webkit-transform:scale(.5)来进行缩小一倍,这样就得到border为0.5的边框

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <style>
  9. .div{
  10. width: 100%;
  11. height: 100px;
  12. border-top: 1px solid aqua;
  13. posititon:relative;
  14. }
  15. .div::after{
  16. content: '';
  17. position: absolute;
  18. left: 0;
  19. bottom: 0;
  20. box-sizing: border-box;
  21. width: 200%;
  22. height: 1px;
  23. transform: scale(.5);
  24. transform-origin: 0 0;
  25. pointer-events: none;
  26. background-color: aqua;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div class="div"></div>
  32. </body>
  33. </html>Copy to clipboardErrorCopied

效果展示:

img

发表评论

表情:
评论列表 (有 0 条评论,225人围观)

还没有评论,来说两句吧...

相关阅读