2021-11-13

标题1px边框的实现?

加粗样式方案一:

采用媒体查询的方式,如果在非高清屏,则设置边框为1px;如果是高清屏,且dpr是2,那么设置边框为0.5px;如果是高清屏,且dpr是3,那么设置边框为0.3333px

```css
.border {
    border: 1px solid #ccc;
}
@media screen and (-webkit-min-device-pixel-ratio:2) {
    .border {
        border: 0.5px solid #ccc
    }
}
@media screen and (-webkit-min-device-pixel-ratio:3) {
    .border {
        border: 0.3333px solid #ccc
    }
}
```

** 方案二:**

通过css3缩放实现

通过伪元素选择器创建一个伪元素,边框为1px,并且将尺寸设置为父元素的2倍。然后再通过transform:scale将元素缩小到50%

````css
.radius-border {
    position: relative;
}
@media screen and (-webkit-min-device-pixel-ratio:2) {
    .radius-border:before {
        content: "";
        pointer-events:none; /*防止点击处触发*/
        box-sizing:border-box;
        position: absolute;
        width: 200%;
        height: 200%;
        left: 0;
        top: 0;
        border: 1px solid #ccc;
        transform: scale(0.5);
        transform-origin: 0 0;
    }
}
@media screen and (-webkit-min-device-pixel-ratio:3) {
    .radius-border:before {
        content: "";
        pointer-events:none; /*防止点击处触发*/
        box-sizing:border-box;
        position: absolute;
        width: 200%;
        height: 200%;
        left: 0;
        top: 0;
        border: 1px solid #ccc;
        transform: scale(0.3);
        transform-origin: 0 0;
    }
}
````
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值