阅读604 返回首页    go 阿里云 go 技术社区[云栖]


手机实现1像素边框显示

问题需求:页面设置边框1像素时,电脑端显示是正常的,手机端会显示比正常粗一点。
1、给需要显示1像素边框的元素添加伪类元素,设置边框为1px。注意:这个时候和直接在元素本身设置边框是一样的效果,达不到真正显示1像素的问题。
2、然后用media 媒体查询,设置伪类元素的缩放比例。

  1. @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) {
  2. .border-1px::after{
  3. -webkit-transform: scaleY(0.7);
  4. }
  5. }
  6. @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {
  7. .border-1px::after{
  8. -webkit-transform: scaleY(0.5);
  9. }
  10. }
 3、完整示例

  1. html
  2. <div class="tab border-1px"></div>
  3. css
  4. .tab{
  5. display:flex;
  6. width:100%;
  7. height:40px;
  8. line-height:40px;
  9. position:relative;
  10. }
  11. .tab:after{
  12. display:block;
  13. position:absolute;
  14. width:100%;
  15. left:0;
  16. bottom:0;
  17. border-top:1px solid rgba(7,17,27,0.1);
  18. content:'';
  19. }
  20. base.css
  21. @media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) {
  22. .border-1px::after{
  23. -webkit-transform: scaleY(0.7);
  24. }
  25. }
  26. @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2) {
  27. .border-1px::after{
  28. -webkit-transform: scaleY(0.5);
  29. }
  30. }

最后更新:2017-07-10 16:32:30

  上一篇:go  2017年物联网发展的八大趋势
  下一篇:go  物联网无线传感器技术的十大典型应用实例