工作中要想完成以下实际效果:
在 div 标识中加上一个 relative 精准定位,随后应用肯定精准定位 absolute 在最右边
<div class="content"> <div class="bar first" style="width:100%"> <span>688</span> </div> <div class="bar second" style="width:50%"> <span>688</span> </div> <div class="bar third" style="width:80%"> <span>688</span> </div> </div>
自身的处理方法
.bar { height: 12px; margin-top: 1px; position: relative; &.first { background-image: linear-gradient(90deg, #ecf848 0%, #f9eab9 99%); } &.second { background-image: linear-gradient(90deg, #f5b549 0%, #f9d6b9 100%); } &.third { background-image: linear-gradient(90deg, #f57849 0%, #f9c7b9 100%); } span{ position: absolute; right: 0; font-size: 12px; color: rgba(255, 255, 255, 0.7); } }
結果:
依照上边的书写,只有是 span 标识的最右边和父标识div 的最右边重合,没法完成总体目标。处理方法,测算 span标识的值,随后right 设定为测算的长短
.bar { height: 12px; margin-top: 1px; position: relative; &.first { background-image: linear-gradient(90deg, #ecf848 0%, #f9eab9 99%); } &.second { background-image: linear-gradient(90deg, #f5b549 0%, #f9d6b9 100%); } &.third { background-image: linear-gradient(90deg, #f57849 0%, #f9c7b9 100%); } span{ position: absolute; left: calc(100% + 8px); font-size: 12px; color: rgba(255, 255, 255, 0.7); } }
left 参考的总宽是 父器皿 的总宽
.bar { height: 12px; margin-top: 1px; position: relative; &.first { background-image: linear-gradient(90deg, #ecf848 0%, #f9eab9 99%); } &.second { background-image: linear-gradient(90deg, #f5b549 0%, #f9d6b9 100%); } &.third { background-image: linear-gradient(90deg, #f57849 0%, #f9c7b9 100%); } span{ position: absolute; right:0; transform: translate(100%, 0); font-size: 12px; color: rgba(255, 255, 255, 0.7); } }
transform: translate 参考的总宽是本身內容的总宽
到此这篇有关CSS 表明横着进展条最终显示信息文本的完成编码的文章内容就详细介绍到这了,大量有关css横着进展条显示信息文本內容请检索脚本制作之家之前的文章内容或再次访问下边的有关文章内容,期待大伙儿之后多多的适用脚本制作之家!