Vertical progress bar containing data percentage and CSS not rendering properly

I have been attempting to create a vertical progress bar using the data-procentage tag. I have almost completed it, but for some reason, the progress bars are not aligned properly and I can't figure out why.

This is what my code looks like so far:

The HTML:

    ul li {
       float: left;
       list-style: none;
       margin:0 40px;
    }

    ul li a {
       text-decoration:none;
    }

    .progressbar {
       background:black;
       border-radius: 0 3px 3px 0;
       height: 30px;
       margin: 0px 0 0 0px;
       -webkit-transform: rotate(-90deg);
    }

    .title {
       color: black;
       font: 12px 'Arial';
    }

    .progressbar2 {
       border-radius: 0 3px 3px 0;
       height: 30px;
       margin: 0px 0 0 0px;
    }

    .progressbar2:after {
       content: attr(data-procentage) '%';
       color: black;
       font: 14px 'Arial';
    }
<div id="progress">
      <ul>
        <li>
            <div class="progressbar2" data-procentage="53.40"></div>
            <div class="progressbar" style="width:53.45%" data-procentage="53.40"></div>
            <a href="#"><span class="title">New York</span></a>
        </li>
        <li>
            <div class="progressbar2" data-procentage="13.25"></div>
            <div class="progressbar" style="width:13.25%" data-procentage="13.25"></div>
            <a href="#"><span class="title">Los Angeles</span></a>
        </li>
        <li>
            <div class="progressbar2" data-procentage="10.37"></div>
            <div class="progressbar" style="width:10.37%" data-procentage="10.37"></div>
            <a href="#"><span class="title">Washington D.C.</span></a>
        </li>
        <li>
            <div class="progressbar2" data-procentage="22.98"></div>
            <div class="progressbar" style="width:22.98%" data-procentage="22.98"></div>
            <a href="#"><span class="title">San Francisco</span></a>
        </li>
      </ul>
    </div>

If you'd like to see a demo, check out this fiddle http://jsfiddle.net/mvqg3d0n/

Could someone please provide assistance with aligning these progress bars? Your help would be greatly appreciated.

Answer №1

To customize your progress bar, adjust the CSS code below to change the rotation origin point to the bottom left corner. To align properly, you will need to shift it 30px to the right using the translate property.

-webkit-transform-origin: 0% 100%;
-webkit-transform: translate(30px,0px) rotate(-90deg);

Remember to include the unprefixed version for browsers other than Webkit (such as Firefox).

transform-origin: 0% 100%;
transform: translate(30px,0px) rotate(-90deg);

Ensure that all li items have consistent widths to maintain the correct size of the progress bar.

If you are unfamiliar with the purpose of the data- attribute, note that it does not determine the width of the bar. Instead, you can use it within your .progressbar2 class to store information accessible via CSS content or for Javascript functionality. It is not necessary in the .progressbar class unless utilized elsewhere.

Answer №2

ul li {
  display: inline-block;
  list-style: none;
  margin: 0 40px;
  text-align: center;
}
ul li a {
  text-decoration: none;
  display: block;
}
.progressbar {
  background: black;
  border-radius: 0 3px 3px 0;
  height: 30px;
  margin: 0px 0 0 0px;
  -webkit-transform: rotate(-90deg);
  display: inline-block;
}
.title {
  color: black;
  font: 12px'Arial';
}
.progressbar2 {
  border-radius: 0 3px 3px 0;
  height: 30px;
  margin: 0px 0 0 0px;
}
.progressbar2:after {
  content: attr(data-procentage)'%';
  color: black;
  font: 14px'Arial';
}
<div id="progress">
  <ul>
    <li>
      <div class="progressbar2" data-procentage="53.40"></div>
      <div class="progressbar" style="width:53.45%" data-procentage="53.40"></div>
      <a href="#"><span class="title">New York</span></a>
    </li>
    <li>
      <div class="progressbar2" data-procentage="13.25"></div>
      <div class="progressbar" style="width:13.25%" data-procentage="13.25"></div>
      <a href="#"><span class="title">Los Angeles</span></a>
    </li>
    <li>
      <div class="progressbar2" data-procentage="10.37"></div>
      <div class="progressbar" style="width:10.37%" data-procentage="10.37"></div>
      <a href="#"><span class="title">Washington D.C.</span></a>
    </li>
    <li>
      <div class="progressbar2" data-procentage="22.98"></div>
      <div class="progressbar" style="width:22.98%" data-procentage="22.98"></div>
      <a href="#"><span class="title">San Francisco</span></a>
    </li>
  </ul>
</div>

Answer №3

To ensure consistency in the width of list items, it is important to set a fixed width for each item. Currently, the varying text lengths result in different widths for each element, which distorts the overall appearance of the percentage bars:

ul li {
    float: left;
    list-style: none;
    margin: 0 40px;
    width: 200px;
}

In the above code snippet, I have used 200px as an illustrative example. Feel free to adjust this value according to your requirements. If you prefer all items to be aligned to the left, simply set their width to 100% like so:

ul li {
    float: left;
    list-style: none;
    margin: 0 40px;
    width: 100%;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to vertically center text with button label in Bootstrap 4

I have a simple objective: I want to align a line of text to the left and a button to the right, with the text vertically aligned to the button's label. I've tried adjusting padding and margins without success. I feel like there must be an easy s ...

Changing <br> to a newline ( ) using JSOUP

Is there a way to efficiently replace all occurrences of <br> with a new line character (\n) in HTML using Jsoup? I'm looking for a clean solution that will result in the Element#text() outputting plain text without any HTML, but with &bsol ...

The function of modal in JavaScript is not working properly

I am encountering a problem with my web page that is running on Wildfly 12. It is a simple Java EE project that I developed in Eclipse Neon. The issue arises when I try to use Bootstrap modals, as every time I attempt to open or use the methods in a JavaSc ...

Adaptable positioning determined by screen and window width exclusively

After searching through numerous resolved dynamic positioning questions, I have not found any solutions that are helpful to my situation. Here is a description of the page... +-----------------------------------------------------------------------+ | +--- ...

In Chrome, the height of 100% is not functioning properly within the <div> element

I've been struggling with a problem that I've searched the internet for solutions to, but haven't been able to resolve. The issue revolves around an iframe containing a page that loads specific CSS rules. html, body { position: relative; he ...

The unattractive visual outcome of Three.js rendering

My goal is to generate a 3D map of buildings using Three.js, based on a 2D SVG file. The process involves taking each path from the SVG, utilizing transformSVGPath from d3.js to create a shape, and then extruding it as shown below: var material = new THRE ...

Use CSS to target elements with IDs that have been generated randomly

Unfamiliar with the specific IDs, this markup presents a challenge: #product-20625055 { background-color: #FC0; } #product-66980342 { background-color: #0CF; } #product-54722210 { background-color: #F0C; } <div class="product" id="product-20625055"&g ...

Adjust the color of the icon depending on the value

I am new to Angular2 and I'm looking for a way to dynamically change the CSS of an icon based on specific values. Here is the code in HTML: <li><i class="fa fa-check" [style.color]="'switch(types)'"></i>{{ types }}</l ...

What is the best way to implement a clickable grid row using CSS?

My grid layout consists of 1 row and 4 columns, with the row occupying 85% of the width. I want the entire row to change color when hovered over and be clickable to access another page. Currently, the row changes colors when hovered over and is clickable, ...

Guide for executing Java code and displaying HTML form fields concurrently in JSP

I have created a JSP page with form fields and Java code in scriptlets. I have imported the Java code into the JSP page and created an object to call the functions of that Java class. When I run the JSP, the page remains blank until all the Java code has ...

Creating a div background that is transparent within a Bootstrap modal

Here is the HTML (Bootstrap) code I have: <div modal="showModal" close="cancel()"> <div class="modal-header text-center"> <h2>Members who shortlisted you </h2> </div> <div class="modal-body"> ...

Utilizing onmouseover and onmouseoff events with images to dynamically alter text content

I have 6 images and I want to dynamically change the text next to them based on which image is being hovered over with the mouse. Even though I attempted to achieve this using JavaScript with the onmouseover and onmouseout events, my code doesn't see ...

Selection determines the value of two fields

This form has predefined values that are used to create a link, but the issue is that these values vary depending on the location. Can you assist me with this problem? <input type="radio" id="iconapp1" name="department" value="1250"/><label for ...

What's the best way to horizontally align two logos in the navigation bar?

Has anyone successfully placed 2 logos on the navbar in Materialize Framework side by side? I'm struggling to make it work and could use some help. Here is my CodePen for reference. I've experimented with the display property but haven't ...

Adaptive Table Layout that Creates a Page-breaking Design

I have a page layout with three columns: a fixed-width left-hand navigation, a responsive content column, and a fixed-width right-hand navigation. The issue arises when the content in the middle column includes HTML tables that sometimes exceed the availab ...

-webkit-margin creates excess spacing on text elements

It just dawned on me, not only in webkit browsers. All texts within p tags or h1 tags seem to have extra spacing above and below the text. In my investigation in Chrome, I came across this: user agent stylesheet -webkit-margin-before: 1em; -webkit-ma ...

Strange spacing below body element discovered while browsing website in Firefox 7

Currently, I am facing an issue on my website in Firefox 7. A margin is causing the gradient in #wrapper to shift upwards from the bottom, disrupting the layout. Despite resetting the margin to 0 on body and html, I am unable to pinpoint the root of the pr ...

Issues with Bootstrap Input Group functionality

I am attempting to align multiple form elements in a row, however I am encountering some unusual behavior. My goal is to have the checkbox, label, number input, and select dropdown appear in the same line as shown in this image: https://i.sstatic.net/rARZ ...

Showcasing the Characteristics of Products in a Table on Prestashop

Dealing with PrestaShop. I have configured attributes for a product and I want to showcase them in a table format similar to this example: The table should display the Paper Size across the top, with each row representing the quantity of paper. In my ad ...

Creating dynamic animations by shifting the hue of an image on a canvas

Recently, I've been exploring the world of canvas tags and experimenting with drawing images on them. My current project involves creating a fake night/day animation that repeats continuously. After trying various approaches like SVG and CSS3 filters ...