在工作中想要实现如下效果:
在 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横向进度条显示文字内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
官方文档 https://developers.weixin.qq.... index.wxml view class="container"...
不知道从什么时候开始,在网络上到处可以看到div+css,到底什么是div+css呢?难...
content [Ctrl+A 全选 注: 引入外部Js需再刷新一下页面才能执行 ] 终于见识了这...
本文学习的内容主要如下所示: 1.关闭按钮 2.Carets 3.快速设置浮动 4.内容区域...
Dreamweaver中的代码想要插入注释,该怎么添加呢?下面我们就来看看详细的教程。...
效果图: 整体效果: 视频加载: 拍照: 第一步:创建HTML元素 首先,我们要创建...
运维工程师这个岗位不同于后端开发岗位,到底运维工程师平时做什么? 老司机告诉...
下面介绍一下div嵌套div时margin不起作用的解决方案。 顺便科普下margin的定义和...
链接可以制作 WML 卡片来显示 WML 的锚功能,图像可以制作 WML 卡片来显示图像. ...
通过 display:bolck/none 完成一个菜单栏的效果 图1: 首先下面是已经完成的一...