What is the best way to invert the positioning of the li elements to move upwards?

https://i.stack.imgur.com/mZaoS.png

Seeking assistance on adjusting the height of bars to start from the bottom and go upwards instead of starting from the top position and going downwards. The JavaScript code below is used to generate the li elements and set their heights:

var rootContainer;
var barContainer;

var randomNumberButton;
var mergeSortButton;
const NUM_BARS = 70;

function initApp() {
rootContainer = document.querySelector(".algo-container");
barContainer = document.querySelector(".bar-container");

randomNumberButton = document.getElementById("random-number");
mergeSortButton = document.getElementById("merge-sort");

randomNumberButton.addEventListener("click", handleRandomNumberButton);
mergeSortButton.addEventListener("click", handleMergeSortButton);
}

function handleRandomNumberButton(e) {
barContainer.innerHTML = "";

let numbers = [];
for (let i = 0; i < NUM_BARS; i++) {
numbers.push(generateRandomNumber(340, 100));
}

let ul = document.createElement("ul");
ul.style.height = "100%";
ul.style.width = "100%";

for (let i = 0; i < NUM_BARS; i++) {
let li = document.createElement("li");
li.style.backgroundColor = "#576cff";
li.style.width = "8px";
li.style.marginLeft = "1px";
li.style.marginRight = "6px";
li.style.height = `${numbers[i]}px`;
ul.appendChild(li);
}

barContainer.appendChild(ul);
}

function handleMergeSortButton(e) {}

function generateRandomNumber(b, a) {
return Math.round(Math.random() * (b - a) + a);
}

window.addEventListener("DOMContentLoaded", initApp);
li {
display: inline-block
}
<div class="algo-container"></div>
<div class="bar-container"></div>
<input id="random-number" type="button" value="Random" />
<input id="merge-sort" type="button" value="Merge - sort" />

Answer №1

To change the appearance of your stats, you can apply a CSS transform to the container:

.container {
    transform: scaleY(-1);
}

By using this transformation, the height of the container is reversed with a negative value.

Another option is to convert the container into a Flexbox and align its items to the bottom:

.container {
    display: flex;
    align-items: flex-end;
}

Answer №2

To achieve the desired effect, you may rotate your container by 180deg. Simply apply a CSS transform to your container element as shown below:

.container {
    transform:rotate(180deg);
}

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

What causes the variation in size between the next/image and img HTML elements?

Two Images, Different Sizes! https://i.sstatic.net/vpoNG.jpg There seems to be a discrepancy in size between the image rendered by the next/img component and the one displayed using the img element. Interestingly, they both use the same image source and ar ...

Is there a way in jQuery Validation to apply a rule to the entire form rather than just individual elements within the form?

I am facing an issue with a form where each element has its own custom rules that work perfectly. However, the form cannot be submitted unless values are provided for at least one of its elements. It seems like this is a rule for the entire form rather th ...

Combine strings in PHP with an alert box in JavaScript

Is there a way to concatenate a string in a JavaScript alert box? I want the first part of the alert box to be a simple text, while the second part is a string retrieved from a MySQL table. $myname = $row["name"]; echo ' <scri ...

Position an element to the right inside its parent container with varying width in Internet Explorer 7 or earlier

I am trying to align a button to the right edge of a table inside a container-div that has no set width. The goal is to have the button float on the right side of the table, lining up with its right edge. While my current approach works in most browsers, i ...

The best way to avoid routing before certain async data in the Vuex store has finished loading

I am facing a challenge in my application where I require certain data to be loaded into the VueX store before routing can commence, such as user sessions. An example scenario that showcases a race condition is as follows: // Defined routes { name: &ap ...

Difficulty with obtaining .responsetext in AJAX and PHP

On my real estate website, I have a form for users to 'Add a Property'. Although I will implement form validation later on, here is the current html/js code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR ...

Creating a column in CSS that maximizes width without utilizing 100% or causing text wrap

Trying to keep a three-column div from spilling over the page can be tricky. The first two columns must not exceed 200px, while the third column should be at least 280px wide. The issue arises when there is a table in the third column with long sentences i ...

Interactive rotating display with constantly updating information

Recently I started learning angularJS and I must say, I am already hooked. I have developed a website that pulls data from JSON files (created by external scripts) locally to show real-time information on various pages. Now, I want to include a sliding car ...

Interpolating strings in a graphQL query

Exploring the world of Gatsby and its graphQL query system for asset retrieval is a fascinating journey. I have successfully implemented a component called Image that fetches and displays images. However, I am facing a challenge in customizing the name of ...

Customizing the colors of the Input field in the Material UI Text Field component with CSS styling can elevate the overall

import { TextField } from "@mui/material"; import { FunctionComponent } from "react"; interface IProps { type: string; label: string; color: | "error" | "primary" | "secondary" | &quo ...

Unable to utilize external JavaScript files in Angular 8

I've been working on integrating an HTML template into my Angular project and for the most part, everything is going smoothly. However, I've encountered an issue where my JS plugins are not loading properly. I have double-checked the file paths i ...

The box-shadow is evenly distributed on the top and bottom as well as on the right and left sides

.box { background: blue; width: 500px; height: 550px; margin: 25px 0 25px 25px; border-width: 30px; border-style: solid; border-color: blue grey yellow green; box-shadow: 20px 20px 0 10px purple, -20px 20px 0 10px purple, 20 ...

Is there a way for me to retrieve the element that is linked to the ng-disabled attribute?

Is there a way to access the element with the ng-disabled attribute inside the function without passing it as a parameter? Here is the HTML element: <input class="needsDisabling" ng-disabled="isFieldDisabled()" type="text"> The isFieldDisabled fu ...

Stop the change event from occurring on a textarea when the user clicks on an external cancel button

In a particular scenario, there is a textarea with an autosave feature triggered by the change event. When the textarea is focused on, Save and Cancel buttons appear at the bottom, providing users with options in case they prefer not to simply click outsid ...

Revamp MUI class names with React Material UI's innovative randomization and elimination

Can names be randomized or Mui-classNames removed? https://i.stack.imgur.com/J6A9V.png Similar to the image displayed? (All CSS class names would be jssXXX) Appreciate your assistance. ...

the battle between width and max-width for creating responsive web layouts

Many tutorials suggest using max-width:100% for images in responsive web design to ensure flexibility. However, why is it also possible to achieve the same result by using width:100%? ...

Invert the motion within a photo carousel

Is there anyone who can assist me with creating a unique photo slider using HTML, CSS, and JS? Currently, it includes various elements such as navigation arrows, dots, and an autoplay function. The timer is reset whenever the arrows or dots are clicked. Ev ...

Utilizing a function from a library in an Object within a Typescript environment

Currently, I am working on assigning a field within my interface to a function from an external library in the following manner: import { Accelerometer, } from 'expo-sensors'; type SensorInterface = { permChecker: () => Promise<Permiss ...

Customize the background color in VueJS based on user roles

I am currently working on a vuejs project with different user levels. In the "user" level (and public area), there is a background image, while in the "admin" level, a plain white background is displayed. I have read that using style tags in the template ...

While working in Next.js, I utilized an `<Image />` tag with a link to an image, only to encounter an unexpected error

I've attempted it numerous times, but the error persists. I even went ahead and created the next.config.js file. module.exports = { images: { domains: ['link.papareact.com', ], }, }; Error: The src prop (https://links.pap ...