【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

相关推荐
愈努力俞幸运1 天前
volta教程 下载安装使用
前端
冰暮流星1 天前
javascript短路运算
开发语言·前端·javascript
qq_419854051 天前
移动端开发:h5应用开发
前端
alonewolf_991 天前
JVM调优实战与常量池深度解析:从Arthas到字符串常量池
前端·jvm·chrome
zuozewei1 天前
零基础 | 从零实现ReAct Agent:完整技术实现指南
前端·react.js·前端框架·智能体
白柚Y1 天前
react的hooks
前端·javascript·react.js
vueTmp1 天前
个人开发者系列-上线即“爆火”?那些掏空你 Cloudflare 额度的虚假繁荣
前端·nuxt.js
i7i8i9com1 天前
React 19+Vite+TS学习基础-1
前端·学习·react.js
CHANG_THE_WORLD1 天前
switch case 二分搜索风格
前端·数据库
我的golang之路果然有问题1 天前
实习中遇到的 CORS 同源策略自己的理解分析
前端·javascript·vue·reactjs·同源策略·cors