【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

相关推荐
摘星编程32 分钟前
在OpenHarmony上用React Native:Spinner自定义样式
javascript·react native·react.js
摇滚侠37 分钟前
css 设置边框
前端·css
星爷AG I1 小时前
9-24 视觉叙事(AGI基础理论)
前端·人工智能
2501_940007891 小时前
Flutter for OpenHarmony三国杀攻略App实战 - 鸿蒙适配与打包发布
前端·flutter
css趣多多1 小时前
跨域问题及Vue项目中本地/线上解决方法核心总结
前端
光影少年1 小时前
前端 AIGC
前端·aigc
启山智软1 小时前
供应链商城核心功能模块清单
java·前端·开源
徐同保1 小时前
Claude Code提示词案例(开发复杂动态路由详情页面)
前端
Σdoughty1 小时前
python第三次作业
开发语言·前端·python
是萧萧吖1 小时前
每日一练——有效的括号
java·开发语言·javascript