【HTML】1px边框与1px分割线

对比图

  • 箭头标注的是处理过的

1px分割线

  • 使用transform的scaleY进行缩小

html 复制代码
 <div class="mini-heriz"></div>
 <br>
 <div style="border: solid 1px black; width: 300px;height: 1px;"></div>
<style>
.mini-heriz {
  width: 300px;
  position: relative;
  height: 1px;
}

.mini-heriz::before{
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: black;
  content: '';
  transform: scaleY(.5);
}
</style>



1px边框

  • 宽高设为父元素的200%

    • width: 200%
    • height: 200%
  • 利用伪元素beforeafter进行绘制边框

  • 使用transform: scale(0.5)缩小一半

  • 最后使用transform-origin: left top设置缩放位置

    • left x轴沿左边开始缩放
    • top y轴沿顶部缩放
html 复制代码
 <div class="mini-border"></div>
 <br />
 <div style="border: solid 1px black; width: 100px; height: 100px;border-radius: 5px;"></div>

<style>
.mini-border {
  position: relative;
  width: 100px;
  height: 100px;
}

.mini-border::before {
  border-radius: 5px;
  border: solid 1px black;
  width: 200%;
  height: 200%;
  content: "";
  left: 0;
  top: 0;
  transform-origin: left top;
  position: absolute;
  transform: scale(0.5);
}
</style>

End

2024/3/12 16:56

相关推荐
半兽先生4 分钟前
WebRtc 视频流卡顿黑屏解决方案
java·前端·webrtc
南星沐1 小时前
Spring Boot 常用依赖介绍
java·前端·spring boot
孙_华鹏2 小时前
手撸一个可以语音操作高德地图的AI智能体
前端·javascript·coze
zhangxingchao2 小时前
Jetpack Compose 动画
前端
@PHARAOH2 小时前
HOW - 缓存 React 自定义 hook 的所有返回值(包括函数)
前端·react.js·缓存
拉不动的猪2 小时前
设计模式之--------工厂模式
前端·javascript·架构
前端开发张小七2 小时前
16.Python递归详解:从原理到实战的完整指南
前端·python
陈奕迅本讯2 小时前
操作系统 3.6-内存换出
前端
Aphelios3803 小时前
TaskFlow开发日记 #1 - 原生JS实现智能Todo组件
java·开发语言·前端·javascript·ecmascript·todo
前端开发张小七3 小时前
15.Python正则表达式入门:掌握文本处理的利器
前端·python