【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

相关推荐
liuyouzhang7 分钟前
将基于Archery的web数据库审计查询平台封装为jdbc接口的可行性研究(基于AI)
前端·数据库
码事漫谈6 小时前
大模型输出的“隐性结构塌缩”问题及对策
前端·后端
这儿有一堆花6 小时前
前端三件套真的落后了吗?揭开现代 Web 开发的底层逻辑
前端·javascript·css·html5
.Cnn6 小时前
JavaScript 前端基础笔记(网页交互核心)
前端·javascript·笔记·交互
醉酒的李白、7 小时前
Vue3 组件通信本质:Props 下发,Emits 回传
前端·javascript·vue.js
anOnion7 小时前
构建无障碍组件之Window Splitter Pattern
前端·html·交互设计
NotFound4867 小时前
实战分享Python爬虫,如何实现高效解析 Web of Science 文献数据并导出 CSV
前端·爬虫·python
徐小夕8 小时前
PDF无限制预览!Jit-Viewer V1.5.0开源文档预览神器正式发布
前端·vue.js·github
WangJunXiang68 小时前
Haproxy搭建Web群集
前端
阿部多瑞 ABU8 小时前
《智能学号抽取系统》V5.9.5 发布:精简代码,修复移动端文件读取核心 Bug
vue·html·bug