Problem DescriptionI want to achieve the following results at work: SolutionAdd a relative positioning to the div tag, and then use absolute positioning to position it on the far right. <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> Your own solution .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); } } result: According to the above writing, the rightmost side of the span tag can only overlap with the rightmost side of the parent tag div, which cannot achieve the goal. The solution is to calculate the value of the span tag and then set right to the calculated length. Considering that the above implementation needs to rely on js and is too troublesome, think about whether there is a way to achieve the goal only through CSS?Solution 1: left: 100%;.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); } }
Solution 2: right:0; transform: translate(100%, 0).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); } }
This concludes this article about the CSS code for implementing the text displayed at the end of a horizontal progress bar. For more relevant CSS horizontal progress bar text display content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: mysql security management details
>>: Detailed process of NTP server configuration under Linux
CSS Selectors Setting style on the html tag can s...
1. What is a servlet 1.1. Explain in official wor...
1. Some problems encountered I remember when we w...
Preface Yesterday, there was a project that requi...
In react, if you modify the state directly using ...
Table of contents 1. Installation of JDK1.8 under...
Installation Environment WIN10 VMware Workstation...
There are many database management tools for MySQ...
When we edit a layout, we usually use horizontal ...
Use the FRAME property to control the style type ...
Because the version I used when I was learning wa...
There are two types of dead link formats defined b...
Sometimes when requesting certain interfaces, you...
Today I recommend such an open source tool for ex...
register The front-end uses axios in vue to pass ...