html 给文本两端加虚线自适应

效果图:

复制代码
<div class="separator">
    文本
</div>

.separator {
  width: 40%;
  border-style: dashed;
  display: flex;
  align-items: center;
  color: #e2e2e2;
  font-size: 14px;
  line-height: 20px;
  border-color: #e2e2e2;
  border-width: 0;
}

.separator::before {
  content: '';
  flex: 1;
  box-sizing: border-box;
  height: 1px;
  border-color: inherit;
  border-style: inherit;
  border-width: 2px 0 0;
  margin-right: 5px;
  padding: 0;
  outline: none;
}

.separator::after {
  content: '';
  flex: 1;
  box-sizing: border-box;
  height: 1px;
  border-color: inherit;
  border-style: inherit;
  border-width: 2px 0 0;
  margin-left: 5px;
  padding: 0;
  outline: none;
}
相关推荐
ZC跨境爬虫2 小时前
3D 地球卫星轨道可视化平台开发 Day13(卫星可视化交互优化+丝滑悬停聚焦)
前端·算法·3d·json·交互
qq_419854052 小时前
animation 和 transition
前端
weixin199701080162 小时前
《孔夫子旧书网商品详情页前端性能优化实战》
前端·性能优化
spring2997923 小时前
SpringBoot返回文件让前端下载的几种方式
前端·spring boot·后端
木斯佳3 小时前
前端八股文面经大全:正泰电气前端实习一面(2026-04-19)·面经深度解析
前端·面试·笔试·校招·面经
江-月*夜3 小时前
vue3 wordcloud2.js词云使用
开发语言·javascript·vue.js
用户69371750013843 小时前
你每天用的 AI,可能真的被“投毒”了
前端·后端·ai编程
吴声子夜歌3 小时前
Vue3——Vuex状态管理
前端·vue.js·vue·es6
qq_12084093713 小时前
Three.js 工程向:Frustum Culling 与场景分块优化实战
前端·javascript
漫游的渔夫3 小时前
从 Fetch 到 RAG:为什么你的 AI 知识库总是“胡言乱语”?
前端·人工智能