0% found this document useful (0 votes)
19 views4 pages

CSS Step Progress Bar Example

This document contains code for a multi-step progress bar including HTML, CSS, and JavaScript. The HTML contains the progress bar markup with four numbered steps. The CSS styles the progress bar and buttons. The JavaScript controls the progress bar by adding and removing a "completed" class from the bullet points on next and previous clicks to change the active step being displayed.

Uploaded by

vatsal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

CSS Step Progress Bar Example

This document contains code for a multi-step progress bar including HTML, CSS, and JavaScript. The HTML contains the progress bar markup with four numbered steps. The CSS styles the progress bar and buttons. The JavaScript controls the progress bar by adding and removing a "completed" class from the bullet points on next and previous clicks to change the active step being displayed.

Uploaded by

vatsal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

WEBTECH Assignment

CECSC04

Screenshot –

HTML –

<!DOCTYPE html>
<html>
    <head>
        <title>2019UCO1710</title>
        <link rel="stylesheet" href="CSS/[Link]">
    </head>
    <body>
        <div class="container">
            <div id="stepProgressBar">
                <div class="step">
                    <p class="step-text">Step 1</p>
                    <div class="bullet">1</div>
                </div>
                <div class="step">
                    <p class="step-text">Step 2</p>
                    <div class="bullet">2</div>
                </div>
                <div class="step">
                    <p class="step-text">Step 3</p>
                    <div class="bullet">3</div>
                </div>
                <div class="step">
                    <p class="step-text">Complete</p>
                    <div class="bullet" id="comp">4</div>
                </div>
            </div>
            <div id="main">
                <button id="previousBtn" >Previous</button>
                <button id="nextBtn">Next</button>
            </div>
        </div>
        <script src="JS/[Link]"></script>
    </body>
</html>

CSS –

#stepProgressBar  {
    display:  flex;
    justify-content:  space-between;
    align-items:  flex-end;
    width:  300px;
    margin:  0  auto;
    margin-bottom:  40px;
}

.step  {
    text-align:  center;
}

.step-text  {
    margin-bottom:  10px;
    color:  #28a745;
}

.bullet {
    border: 1px solid green;
    height: 20px;
    width: 20px;
    border-radius: 100%;
    color:green;
    display: inline-block;
    position: relative;
    line-height:20px;
}

.[Link]  {
    color:  white;
    background-color: green;
}

.[Link]::after {
    content: '';
    position: absolute;
    right: -60px;
    bottom: 10px;
    height: 1px;
    width: 54px;
    background-color: green;
}

button  {
    padding:  5px  10px;
    border:  1px  solid  black;
    
}

.text-center  {
    text-align:  center;
}
  
.container  {
    max-width:  400px;
    margin:  0  auto;
    margin-top:  20px;
    padding:  40px;
}

JavaScript –

const  previousBtn  =  [Link]('previousBtn');
const  nextBtn  =  [Link]('nextBtn');
const  bullets  =  [...[Link]('.bullet')];
const  comp = [Link]('comp');

let currentStep = 1;

[Link]('click',  ()  =>  {
    if(currentStep != 4) {
        bullets[currentStep  -  1].[Link]('completed');
        currentStep  +=  1;
    }
    else {
        [Link] = "green";
        [Link] = "white";
        currentStep++;
    }
});

[Link]('click',  ()  =>  {
    if(currentStep != 1) {
        if(currentStep == 5) {
            [Link] = "white";
            [Link] = "green";
            currentStep--;
        }
        else {
            bullets[currentStep  -  2].[Link]('completed');
            currentStep  -=  1;
        }
    }
});

Common questions

Powered by AI

The separation of HTML, CSS, and JavaScript represents a modular approach central to effective web design, delineating content structure (HTML), presentation (CSS), and behavior (JavaScript). This separation facilitates maintenance and scalability by allowing independent updates to style or functionality without cross-impacting content markup. It improves readability and aids developers in collaboratively working on different facets of the application, streamlining workflow efficiency and adhering to best practices in web development by fostering reusable and cleanly organized code .

Dynamic styling changes using JavaScript, such as modifying element classes to reflect progression, can impair web accessibility if not implemented with assistive technologies in mind. For instance, visual-only changes may not be perceivable by screen readers unless accompanied by appropriate ARIA attributes or status notifications. This poses a risk of alienating users with visual impairments who rely on auditory feedback, emphasizing the need for complementary ARIA roles and live region updates to ensure all status interactions are communicated effectively to all users .

The HTML structure defines a clear hierarchy using <div> elements for each step, ensuring they are visually distinct and identifiable. Each step is encapsulated within a div class="step", and the bullet and textual descriptor are linked hierarchically which allows JavaScript to interact dynamically with individual steps via document.querySelectorAll('.bullet'). This structured configuration supports targeted manipulation, such as adding or removing the class 'completed', to represent progression or regression through steps in the web application .

The optimization for performance and maintainability could involve minimizing DOM manipulation by reducing direct DOM queries within event handlers, possibly caching selectors outside of functions, and utilizing data-* attributes for state management. Code modularization might enhance maintainability, encapsulating progress logic in components or classes. Additionally, optimizing CSS through the use of CSS Grid could afford more control while decreasing reliance on inline styles, and further enhancing JavaScript could involve leveraging frameworks or libraries for more efficient state management and updates .

Event listeners are crucial for enhancing user interaction by dynamically responding to user inputs without requiring a full page reload. Each time a user clicks 'Next' or 'Previous', the event listeners invoke JavaScript functions to alter the DOM, reflecting immediate feedback through visual changes in the progress bar. This increases interactivity by offering a seamless, responsive update to the UI, augmenting user experience by keeping the application intuitive and engaging while minimizing latency that could arise with server-side processing .

CSS flexbox is employed to efficiently distribute space and align the step progress bar’s elements. The use of display: flex; on #stepProgressBar sets up a flexible container, making its children (step elements) flexible items. Properties like justify-content: space-between; and align-items: flex-end; make the distribution of space and alignment vertically consistent, ensuring elements are spaced evenly across the container width and aligned at the bottom for a uniform look. This configuration is crucial in maintaining consistency in appearance regardless of viewport size .

CSS properties are integral to maintaining the visual integrity of the step progress bar by ensuring alignment, spacing, color, and size consistency across elements. Attributes such as display: flex; justify-content: space-between; and align-items: flex-end; organize elements in a linear, evenly spaced layout. The color and size of .bullet elements, controlled by border, color, and width, create a uniform visual identifier for steps, and the use of background-color and color properties manage state indication by evolving their graphical characteristics upon completion .

JavaScript enables step navigation via event listeners added to 'Next' and 'Previous' buttons. When these buttons are clicked, functions are triggered that modify the class list of bullet elements, either adding 'completed' or removing it based on the direction of navigation. This programmatically updates the CSS attributes applied to elements, reflecting state changes visually. The application’s logic checks currentStep to ensure it operates within bounds (1 to 4) for valid interactions, altering the appearance and progression markers accurately .

Direct DOM manipulation in the JavaScript snippet offers the advantage of straightforward, imperative updates that provide immediate visual feedback without involving additional libraries, fostering a lightweight implementation. However, such direct manipulation can become inefficient with larger DOMs due to increased computational cost, potentially resulting in bottlenecks as DOM size increases. It also tends to make code less maintainable and more verbose, often complicating debugging and updates when compared to declarative approaches using libraries like React or Angular .

CSS pseudoelements such as .bullet.completed::after improve both functionality and aesthetics by adding additional styling components that are crucial for visual communication without altering the HTML structure. In this context, they create a line extension to show completed states visually, reinforcing completion status graphically and aiding in user experience by clearly demarcating progress visually. It optimally separates aesthetic styling from logical content, which aids in maintaining clean, semantic HTML markup .

You might also like