zoukankan      html  css  js  c++  java
  • 总结一下各种0.5px的线

    在PC端用1px的边框线,看起来还好,但在手机端看起来就很难看了,而0.5px的分割线会有种精致的感觉。用普通写法border:solid 0.5px red;iPhone可以正常显示,android下几乎所有的浏览器都会把0.5识别为0,即无边框状态.

    原理

    原理就是给需要加边框的元素插入一个伪类,伪类采用绝对定位,然后对伪类添加1px边框,最后进行0.5倍缩放。transform的缩放和旋转默认都是按照元素的中心点来操作的
    outline元素在缩放0.5之前尺寸就是红框元素,缩放后,位置到了红框中心,为了使之依然在左上角,缩放之前我们需进行left:-50%;top:-50%的位移
    图片描述

    0.5px边框

    <div class="first">
      <div class="first-div">
        HELLO WORLD
      </div>
    </div>
    <style>
    .first{
      position: relative;
      font-size: 16px;
    }
    .first .first-div:before{
      content: "";
      position: absolute;
      top: -50%;
      bottom: -50%;
      left: -50%;
      right: -50%;
       200%;
      height: 200%;
      -webkit-transform: scale(0.5);
      transform: scale(0.5);
      border: solid 1px red;
      box-sizing:border-box;
    }
    </style>

    副作用

    当用伪类的绝对定位来实现了边框后,我们在first类和first-div类上的点击事件会失效,因为此时的伪类是绝对定位,而且长宽等于父类元素的长宽,是脱离了文档流覆盖在父类上的,伪类不是真实的DOM元素,没有js点击事件

    • 解决方案

    再写一个绝对定位元素,覆盖在父元素上,层级优先级要高一点

    <div class="first">
      <div class="first-div">
        HELLO WORLD
      </div>
      <div class="click-able" onclick="alert('click')"></div>
    </div>
    <style>
    .first{
      position: relative;
      font-size: 16px;
    }
    .first .first-div:before{
      content: "";
      position: absolute;
      top: -50%;
      bottom: -50%;
      left: -50%;
      right: -50%;
       200%;
      height: 200%;
      -webkit-transform: scale(0.5);
      transform: scale(0.5);
      border: solid 1px red;
      box-sizing:border-box;
    }
    .click-able{
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 10;
    }
      </style>

    0.5px圆角边框

    <div class="round">
      <div class="round-div">
        HELLO WORLD
      </div>
    </div>
    <style>
    .round{
       position: relative;
       font-size: 16px;
     }
    .round .round-div:before{
      content: "";
      position: absolute;
      top: -50%;
      bottom: -50%;
      left: -50%;
      right: -50%;
       200%;
      height: 200%;
      -webkit-transform: scale(0.5);
      transform: scale(0.5);
      border: solid 1px red;
      border-radius: 22px;
      box-sizing:border-box;
    }
    </style>

    0.5px左边线

    <div class="left">
      <div class="left-div">
        HELLO WORLD
      </div>
    </div>
    <style>
    .left{
      position: relative;
      font-size: 16px;
    }
    .left .left-div:before{
      content: " ";
      position: absolute;
      left: 0;
      bottom: 0;
       1px;
      height: 100%;
      border-left: 1px solid red;
      -webkit-transform-origin: 0 0;
      transform-origin: 0 0;
      -webkit-transform: scaleX(0.5);
      transform: scaleX(0.5);
    }
    </style>

    0.5px右边线

    <div class="right">
      <div class="right-div">
        HELLO WORLD
      </div>
    </div>
    <style>
    .right{
      position: relative;
      font-size: 16px;
      display: inline-block;
    }
    .right .right-div:before{
      content: " ";
      position: absolute;
      right: 0;
      bottom: 0;
       1px;
      height: 100%;
      border-right: 1px solid red;
      -webkit-transform-origin: 0 0;
      transform-origin: 0 0;
      -webkit-transform: scaleX(0.5);
      transform: scaleX(0.5);
    }
    </style>

    0.5px底部线

    <div class="bottom">
      <div class="bottom-div">
        HELLO WORLD
      </div>
    </div>
    <style>
    .bottom{
      position: relative;
      font-size: 16px;
    }
    .bottom .bottom-div:before{
      content: " ";
      position: absolute;
      left: 0;
      bottom: 0;
       100%;
      height: 1px;
      border-top: 1px solid red;
      -webkit-transform-origin: 0 0;
      transform-origin: 0 0;
      -webkit-transform: scaleY(0.5);
      transform: scaleY(0.5);
    }
    </style>

    图片描述

    本文转载于:猿2048→https://www.mk2048.com/blog/blog.php?id=hcbka1jabaa

  • 相关阅读:
    WCF后续之旅(3): WCF Service Mode Layer 的中枢—Dispatcher
    .Net 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等)
    我的WCF之旅(13):创建基于MSMQ的Responsive Service
    .net程序集强名称签名实践
    WCF后续之旅(8):通过WCF Extension 实现与MS Enterprise Library Policy Injection Application Block 的集成
    .Net 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等) 2
    WCF后续之旅(6): 通过WCF Extension实现Context信息的传递
    SilverlightCatchWcfError
    WCF后续之旅(7):通过WCF Extension实现和Enterprise Library Unity Container的集成
    WCF后续之旅(4):WCF Extension Point 概览
  • 原文地址:https://www.cnblogs.com/10manongit/p/13031129.html
Copyright © 2011-2022 走看看