Utilizing css calc() in combination with step

We have implemented a CSS-based progress bar.

The key CSS components are outlined below.

.container {
  width: 600px;
  margin: 20px auto;
}

.progressbar {
  margin: 0;
  padding: 0;
  counter-reset: step;
}

.progressbar li {
  list-style-type: none;
  width: 25%;
  float: left;
  font-size: 12px;
  position: relative;
  text-align: center;
  text-transform: uppercase;
  color: #7d7d7d;
}

.progressbar li:before {
  width: 30px;
  height: 30px;
  content: counter(step);
  counter-increment: step;
  line-height: 30px;
  border: 2px solid #7d7d7d;
  display: block;
  text-align: center;
  margin: 0 auto 10px auto;
  border-radius: 50%;
  background-color: white;
}

.progressbar li:after {
  width: 100%;
  height: 2px;
  content: '';
  position: absolute;
  background-color: #7d7d7d;
  top: 15px;
  left: -50%;
  z-index: -1;
}

...............

Here is the HTML structure:

<div class="container">
  <ul class="progressbar">
    <li class="active">login</li>
    <li>choose interest</li>
    ........

A complete example can be viewed at https://jsfiddle.net/wbj7e79p/.

When there are seven steps, the layout becomes problematic. This is due to the fixed width of .progressbar li set to 25%. We attempted using calc(100% / steps) or calc(100% / counter(steps)), but neither solution worked. Any suggestions?


Keep in mind that we are developing a component that generates a dynamic progress bar on the fly, so the actual number of steps is unknown beforehand.

Answer №1

Have you explored the possibilities of flexbox?

body {
  font-family: 'Alegreya Sans', sans-serif;
  margin: 0;
  padding: 0;
}
.container {
  margin: 20px auto;
}
.progressbar {
  margin: 0;
  padding: 0;
  counter-reset: step;
  display: flex;
}
.progressbar li {
  list-style-type: none;
  flex: 1;
  font-size: 12px;
  position: relative;
  text-align: center;
  text-transform: uppercase;
  color: #7d7d7d;
}
.progressbar li:before {
  width: 30px;
  height: 30px;
  content: counter(step);
  counter-increment: step;
  line-height: 30px;
  border: 2px solid #7d7d7d;
  display: block;
  text-align: center;
  margin: 0 auto 10px auto;
  border-radius: 50%;
  background-color: white;
}
.progressbar li:after {
  width: 100%;
  height: 2px;
  content: '';
  position: absolute;
  background-color: #7d7d7d;
  top: 15px;
  left: -50%;
  z-index: -1;
}
.progressbar li:first-child:after {
  content: none;
}
.progressbar li.active {
  color: green;
}
.progressbar li.active:before {
  border-color: #55b776;
}
.progressbar li.active + li:after {
  background-color: #55b776;
}
<h1>Four Steps</h1>
<div class="container">
  <ul class="progressbar">
    <li class="active">login</li>
    <li>choose interest</li>
    <li>add friends</li>
    <li>View map</li>
  </ul>
</div>
<h1> Seven Steps</h1>

<div class="container">
  <ul class="progressbar">
    <li class="active">login</li>
    <li>choose interest</li>
    <li>add friends</li>
    <li>remove</li>
    <li>fix users</li>
    <li>review</li>
    <li>save all</li>
  </ul>
</div>

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

setting the child div's margin in relation to its parent div

Here is my HTML: <div class='mainDiv'> <div class='subDiv'></div> </div> This is the corresponding CSS code: .mainDiv { margin-top: 200px; width: 700px; height: 800px; background-color: red ...

On certain websites, the footer may appear distorted or incorrectly displayed when viewed in the IE 9 web browser

Currently experiencing an issue with the display of the footer in IE9. On some pages, the footer is not properly fixed and overlaps the middle of the content. However, this problem does not occur when using other web browsers. Here is the code that I am c ...

When Socket.emit is called, it outputs <span> elements within a well-structured message

Currently working on a small chat application using Node.js, Express.js, and Socket.IO. However, I'm encountering an issue with formatting. Instead of displaying the message content within <span> tags as intended, it is printing out the actual t ...

What is the suitable condition necessary for optimal functionality?

Greetings all! I am a newbie in the world of development and also new to Stack Overflow. This is my maiden post seeking assistance on the following issue: $(document).ready(function() { $(".header").click(function() { if ($(".header-content"). ...

Capable of retrieving the identification number but incapable of executing a POST request

After successfully retrieving the ID using the router, I encountered an issue when trying to confirm the change of agent status on the retireagent HTML page by clicking the submit button. The error message displayed is "ID is not defined". I am seeking ass ...

If an incorrect feedback message is displayed, the input icon will be disabled

Here is the issue I am encountering: This is the code snippet causing the problem: <div class="col-12"> <div class="form-group has-icon-left"> <label class="form-label" for="first-name-icon&quo ...

Ways to differentiate between a desktop browser width of 1024px and a tablet width of 1024px with the help of jquery

So here's the issue I'm dealing with: I have scroll-based animation functions set up for desktop browsers, and different animations in place for tablet browsers. The challenge is to make these functions work on a desktop with a 1024px dimension. ...

In AngularJS, variables assigned to $scope will not automatically synchronize with HTML elements

I am currently working with 3 files: EventDetails.html, app.js, and EventController.js. Let's take a look at the content of the html file: <html ng-app="eventsApp"> <head>...</head> <body> <div class="container"> & ...

javascript Accumulated arrow management

Currently, I am in the process of developing a rating system. The system involves three hearts that change color when clicked, in an incremental manner (for example, if the second heart is clicked, both the first and second hearts will be colored; if the t ...

The link background color is malfunctioning

I'm having trouble getting the background color to show for the active link class. The border changes to dashed, but the color remains the same. Can anyone help me figure out what's going on? I'm new to CSS and feeling a bit frustrated. Also ...

Is there a jQuery or Javascript alternative to CSS Counter?

Can a counter be implemented that changes the text of a tag directly using jQuery/Javascript? For example, if there were two tags like this: <a>hello</a> <a>bye</a> After executing the jQuery/JS function, the result would be: < ...

The SVG image exceeds the boundaries of the parent column div in bootstrap

I am struggling to make a SVG fit inside a column in a bootstrap div with col-lg-4. I tried using img-fluid, but it did not work as expected. The SVG should automatically adjust its size to fit the parent div. However, that is not happening. .star-ratin ...

Troubleshooting an HTML problem in an ASP.NET web application with web forms

After creating a web app using VS 2015 with a default page and Site.Master, I encountered an issue. The input fields are within a table, while the Save button and message field are outside the table. The Save button is positioned to the right of the table ...

How to create a listview with stylish rounded corners in jQuery mobile using CSS?

I'm attempting to customize the appearance of a jQuery mobile listview using CSS by adding a border radius to each item. Although things seem to be working mostly as expected, I've encountered a problem where only the first and last <li>&l ...

Stop the padding of list items from wrapping when displayed in a horizontal list

My goal is to create a horizontal unordered list (<ul>) with four columns in each row. The number of list items (<li>) may vary and change during runtime. Existing Code and Outcome ul { -webkit-columns: 4; /* Chrome, Safari, Opera */ -m ...

React.JS Tip: Automatically Make Alerts Disappear in 2 Seconds!

How can I make my alert automatically disappear after 2 seconds in React.JS? Currently, the alert only disappears when I manually close it using the fecharAlerta props function. import { useEffect } from "react" import { useState } from "r ...

The input field cannot accommodate the lengthy value in the Mat Select option

When a user selects a value in my mat select, it doesn't display well in the selection box. The text wraps when the selection is opened, but once a choice is made, it gets cut off without proper spacing between the ellipses and the dropdown arrow. Th ...

Utilizing Jquery for toggling HTML elements and styling with CSS

I'm trying to implement a jQuery toggle button that switches between two states below; When I click the Toggle Button/link, everything in picture A (above the red line) should be hidden. Clicking the toggle button again would make it reappear. I&apo ...

HTML input form - issue with combining multiple patterns

Below is a section of my HTML code: <input type="text" #version tabindex="1" class="form-control" id="version" name="version" placeholder="" [(ngModel)]="application.version" required minlength="1" pattern="\d{1 ...

Issue arises during initialization with Slick.js

I recently attempted to implement the slick.js function on my webpage by following the guidelines provided on . I copied the "center mode" function as my Jquery function, but unfortunately, the arrows/buttons and nav-docs were not generated in my slideshow ...