【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

相关推荐
whisperrr.1 小时前
【JavaWeb12】数据交换与异步请求:JSON与Ajax的绝妙搭配是否塑造了Web的交互革命?
前端·ajax·json
烂蜻蜓2 小时前
前端已死?什么是前端
开发语言·前端·javascript·vue.js·uni-app
Rowrey3 小时前
react+typescript,初始化与项目配置
javascript·react.js·typescript
谢尔登3 小时前
Vue 和 React 的异同点
前端·vue.js·react.js
祈澈菇凉8 小时前
Webpack的基本功能有哪些
前端·javascript·vue.js
小纯洁w8 小时前
Webpack 的 require.context 和 Vite 的 import.meta.glob 的详细介绍和使用
前端·webpack·node.js
想睡好8 小时前
css文本属性
前端·css
qianmoQ8 小时前
第三章:组件开发实战 - 第五节 - Tailwind CSS 响应式导航栏实现
前端·css
记得早睡~8 小时前
leetcode150-逆波兰表达式求值
javascript·算法·leetcode
zhoupenghui1689 小时前
golang时间相关函数总结
服务器·前端·golang·time