美文网首页
0.5 px的边框

0.5 px的边框

作者: 你期待的花开 | 来源:发表于2018-11-27 14:47 被阅读9次

实现的原理 :使用伪元素设置1px的边框,然后对边框进行缩放(scaleY)。

  • 设定目标元素的参考位置。
  • 给目标元素设置伪元素before或者after,并设置绝对定位。
  • 给伪元素添加1px的边框。
  • 宽和高设置为 200%。
  • 调整盒子模型的位置,以左上角为基准 transform-origin: 0。
  • 整个盒子模型缩小为0.5。
<!DOCTYPE html>
<html>
<head>
  <title>慕课网网页布局</title>
  <meta charset="UTF-8">
  <style>
    .box1 {
      background-color: red;
      border: 1px solid black;
      width: 100px;
      height: 100px;
      margin-left: 400px;
      margin-top: 100px;
    }

    .box2 {
      background-color: red;
      border: 0.5px solid black;
      width: 100px;
      height: 100px;
      margin-left: 400px;
      margin-top: 200px;
    }

    .box3 {
      position: relative;
      background-color: red;
      width: 100px;
      height: 100px;
      margin-left: 400px;
      margin-top: 200px;
    }
    .box3::after {
      position: absolute;
      content: "";
      border: 1px solid black;
      width: 200%;
      height: 200%;
      transform: scale(0.5);
      transform-origin: 0 0;
    }
  </style>
</head>
<body>
  <div class="box1" ></div> // 添加 1px 的边框
  <div class="box2" ></div> // 添加 0.5px 的边框,无效果
  <div class="box3"></div> // 添加 0.5px 的边框,有效果
</body>
</html>

相关文章

  • 0.5 px的边框

    实现的原理 :使用伪元素设置1px的边框,然后对边框进行缩放(scaleY)。 设定目标元素的参考位置。 给目标元...

  • 0.5px的边框

    有时候我们在做网站的时候 有时需要适配各种手机 iPhone 6设备像素比是2 那么边框为1px的时候 那么css...

  • 0.5px 边框相关

    .dateTip:before{ content: ''; position: absolute; left: 0...

  • 0.5px 细边框

  • 如何实现0.5px边框

    css 高频面试题:如何实现0.5px 的边框其实设置border为0.5px 是不可以的,有些浏览器会把他渲染...

  • 移动端一像素边框

    如何实现在移动端中显示一像素的边框 实现方案一:0.5像素 标准边框语法div{ border: 1px sol...

  • 【css】如何实现移动端敏感的0.5px

    如下几种方法能实现0.5px边框: 1.伪元素2倍尺寸1px边框scale缩小一半 推荐 给容器内设置伪元素,设置...

  • 0.5像素边框

    “度学金”1.0版本中,UI要求列表边框是0.5像素。在IOS手机上border设置成0.5px是可以的,但是在安...

  • 实现0.5px的圆角边框按钮

  • 移动端0.5px边框实现方式

    写在前面在手机页面中,使用1px边框,有事感觉比较粗。使用0.5px会是的页面更加精简。 下面是代码实现 html...

网友评论

      本文标题:0.5 px的边框

      本文链接:https://www.haomeiwen.com/subject/nkmgqqtx.html