Skip to content

CSS 实现 1px 高清边框

Published: at 09:40 AMSuggest Changes

需求

移动端 1px 边框实现

实现

// less
.border-1px{
  position: relative;
  &::before{
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    border:1px solid red;
    color: red;
    height: 200%;
    -webkit-transform-origin: left top;
    transform-origin: left top;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
    pointer-events: none; /* 防止点击触发 */
    box-sizing: border-box;
    @media screen and (min-device-pixel-ratio:3),(-webkit-min-device-pixel-ratio:3){
      width: 300%;
      height: 300%;
      -webkit-transform: scale(0.33);
      transform: scale(0.33);
    }
  }
}

参考文章

CSS 技巧篇 (十):1px 边框解决方案


Previous Post
Vue 深度 CSS 选择器
Next Post
HTML 回车换行与 CSS