What is the best way to align bars at the bottom of a CSS vertical bar chart?

Currently, I am exploring the functionality of two distinct bar charts that I designed using HTML and CSS: one horizontal and the other vertical. Is there a way to shift the bars in my vertical bar chart from the center down to the bottom?

https://i.sstatic.net/291Di.png

body {
    font-family: Arial, Helvetica, sans-serif;
}

/* Global */
.stat-table-horz, .stat-table-vert {
    border-collapse: collapse;
}
.bar {
     background: #0c0;
}

/* Horizontal bar chart */
.stat-table-horz td:first-of-type {
    padding: 5px;
}
.stat-table-horz td:nth-of-type(2) {
    border-top: 1px solid #090;
    border-bottom: 1px solid #090;
    padding: 0;
    width: 240px;
}
.stat-table-horz td .horz-bar {
    height: 30px;
}

/* Vertical bar chart */
.stat-table-vert tr:nth-of-type(2) td {
    padding: 5px;
}
.stat-table-vert tr:first-of-type td {
    border-left: 1px solid #090;
    border-right: 1px solid #090;
    padding: 0;
    height: 160px;
    width: 80px;
}
.stat-table-vert td .vert-bar {
    
}
<body>
<table class="stat-table-horz">
    <tr>
        <td>Health</td>
        <td>
            <!-- First bar -->
            <div class="bar horz-bar" style="width: 10%;"></div>
        </td>
    </tr>
    <tr>
        <td>Attack</td>
        <td>
            <!-- Second bar -->
            <div class="bar horz-bar" style="width: 90%;"></div>
        </td>
    </tr>
    <tr>
        <td>Speed</td>
        <td>
            <!-- Third bar -->
            <div class="bar horz-bar" style="width: 60%;"></div>
        </td>
    </tr>
</table>
<br>
<table class="stat-table-vert">
    <tr>
        <td>
            <!-- First bar -->
            <div class="bar vert-bar" style="height: 10%;"></div>
        </td>
        <td>
            <!-- Second bar -->
            <div class="bar vert-bar" style="height: 90%;"></div>
        </td>
        <td>
            <!-- Third bar -->
            <div class="bar vert-bar" style="height: 60%;"></div>
        </td>
    </tr>
    <tr>
        <td>Health</td>
        <td>Attack</td>
        <td>Speed</td>
    </tr>
</table>
</body>

Link to my original JSFiddle for reference: https://jsfiddle.net/jkantner/b7aa2yu1/

Answer №1

To easily implement vertical alignment, simply include the following CSS code:

.stat-table-vert td {
    vertical-align:bottom;
}

Answer №2

To solve the issue, you can simply add vertical-align: bottom to the parent TD element as shown below:

.table-vertical tr:first-of-type td {
    border-left: 1px solid #333;
    border-right: 1px solid #333;
    padding: 0;
    height: 200px;
    width: 100px;
    vertical-align: bottom;
}

Answer №3

To resolve the issue, you can apply either vertical-align: bottom; or vertical-align: baseline to the td element.

body {
    font-family: Arial, Helvetica, sans-serif;
}

/* Global */
.stat-table-horz, .stat-table-vert {
    border-collapse: collapse;
}
.bar {
     background: #0c0;
}

/* Horizontal bar chart */
.stat-table-horz td:first-of-type {
    padding: 5px;
}
.stat-table-horz td:nth-of-type(2) {
    border-top: 1px solid #090;
    border-bottom: 1px solid #090;
    padding: 0;
    width: 240px;
}
.stat-table-horz td .horz-bar {
    height: 30px;
}

/* Vertical bar chart */
.stat-table-vert tr:nth-of-type(2) td {
    padding: 5px;
}
.stat-table-vert tr:first-of-type td {
    border-left: 1px solid #090;
    border-right: 1px solid #090;
    padding: 0;
    height: 160px;
    width: 80px;
    vertical-align: baseline;
}
.stat-table-vert td .vert-bar {

}
<body>
<table class="stat-table-horz">
    <tr>
        <td>Health</td>
        <td>
            <!-- First bar -->
            <div class="bar horz-bar" style="width: 10%;"></div>
        </td>
    </tr>
    <tr>
        <td>Attack</td>
        <td>
            <!-- Second bar -->
            <div class="bar horz-bar" style="width: 90%;"></div>
        </td>
    </tr>
    <tr>
        <td>Speed</td>
        <td>
            <!-- Third bar -->
            <div class="bar horz-bar" style="width: 60%;"></div>
        </td>
    </tr>
</table>
<br>
<table class="stat-table-vert">
    <tr>
        <td>
            <!-- First bar -->
            <div class="bar vert-bar" style="height: 10%;"></div>
        </td>
        <td>
            <!-- Second bar -->
            <div class="bar vert-bar" style="height: 90%;"></div>
        </td>
        <td>
            <!-- Third bar -->
            <div class="bar vert-bar" style="height: 60%;"></div>
        </td>
    </tr>
    <tr>
        <td>Health</td>
        <td>Attack</td>
        <td>Speed</td>
    </tr>
</table>
</body>

Answer №4

Include this CSS for a flowing effect:

.stat-table-vert td {
        position: relative;
    }
    .stat-table-vert .bar.vert-bar{
        position: absolute;
        bottom: 0;
        width: 100%;
    }

Alternatively, you can also use:

Add this to your CSS:

.stat-table-vert td {
    vertical-align:bottom;
}

Click here for an example on jsFiddle

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

Craft an engaging and dynamic Image map with SVG technology to elevate responsiveness and interactivity

I'm currently working on a website and I need to create two clickable sections on the home page. Each section will lead to a different specialization of the company. To achieve this, I decided to use a square image split into two right-angled triangle ...

Utilizing Gulp variables to create dynamic destination file names?

As a newcomer to gulp, I am curious about the feasibility of achieving my desired outcome. Here is the structure of my projects: root | components | | | component_1 | | styles.scss | | actions.js | | template.html | | ... | componen ...

IE9 causing issues with Angularjs ng-route - views fail to display

I am new to AngularJS and currently working on developing an application using AngularJS along with Coldfusion for database data retrieval. However, I am facing compatibility issues specifically with IE9 (which is the default browser in my office). The ap ...

Issues with NativeScript WebView displaying HTML file

Having trouble loading a local HTML file into a webview in my NativeScript (typescript) application. Despite using the correct path, it's not loading and instead shows an error. <WebView src="~/assets/content.html" /> An error message stati ...

Developing web applications using Express.js and Jade involves connecting CSS stylesheets

I'm currently in the process of developing a web application using Express.js along with some Bootstrap templates. I utilized jade2html for conversion, and while the page loads successfully, it lacks any styling. The following code snippet is what I ...

Issue with PHP's ng-click not functioning properly with Angular JS's dynamic HTML generation

I'm just starting out with Angular JS. I'm trying to create an ng-click event in dynamically generated HTML from PHP, here's the code snippet. var app = angular.module('pageapp',[]); angular.module('pageapp') .filter(& ...

Issue with navigating previous and next slides in Bootstrap carousel

I'm currently facing an issue where when I try to navigate left/right through pictures on my page, it ends up moving slightly downwards instead. Despite following a tutorial to resolve this problem, there seems to be a missing piece of code that I can ...

What impact does reducing the window size have on my header?

While working on a website with a navigation bar, I encountered an issue where the navbar was not responsive. When the window size was reduced, the nav bar shifted to an awkward position vertically, as shown in the first image. The navbar shifts below the ...

"Struggling with getting the text color to change on hover in Tailwind

Today has been a frustrating day as I am diving into the world of tailwindcss and have been struggling with a particular issue. My code is below: <button className="bg-yellow-500 px-4 py-2 hover:text-black text-white"> Some Text Her ...

Difficulty with Line Breaks in Spans

I've noticed that my multi-line address in the footer is not breaking correctly at certain screen widths. Each line of the address is enclosed within a <span> tag with a specific class and then styled either as block or inline-block in the CSS ...

jQuery show/hide functionality allows you to toggle the visibility of elements

I am looking to create a toggle button that expands the menu-wrapper width and hides the sidebar when clicked. Here is the initial CSS styling: #my-wrapper { Width:500px; } #sidebar-wrapper { width:200px; } Upon clicking the button, the CSS will update ...

Obtaining data attributes in Angular 8

I'm working with Angular 8 and I came across an issue. In my code snippet, there are two data attributes assigned to a button element, but only one attribute is showing up. Is this a syntax error or a bug? <button [attr.data-popolamento]="all" [a ...

Angular - Brilliant time selection tool (BTS) The TimePicker feature fails to automatically switch to selecting minutes after choosing the hour

I'm currently implementing the Amazing time picker in my app and I'm facing an issue where it doesn't automatically switch to minutes after selecting the hour. component.html <input type="time" atp-time-picker formControlName="time" cla ...

material-icons appear differently when letter-spacing is applied in iOS browsers

To display levels using star icons from angular material, I wanted the stars to be shown next to each other. I attempted to achieve this by applying letter-spacing: -0.25rem;, but unfortunately it did not render correctly on iOS platforms (resulting in s ...

Need assistance with PHP syntax?

Can you guide me on the correct syntax for creating a target link for a profile? <a href="index.php?p=profile&uid=<?php echo $_SESSION["uid"]; ?>"> <?php echo $_SESSION["username"]; ?></a> The variables I am working with are: ...

Emulate a link click using key input

Hey there! I have this link example: <a href"http://google.es">Link</a> I'm wondering if it's possible to use JavaScript or a similar tool so that when I press a specific key, like the number 5 on the keyboard, it acts as if I click ...

What is the method to make xsl:function return a string value containing HTML tags?

I am currently working on converting a Java function into an XSL:Function specification. The function is responsible for adding HTML tags around substrings. I have encountered some challenges in this process: while the Java code works perfectly with inline ...

Easily input new information into your MySQL database with just a click by utilizing a link through PHP and HTML

Is there a method to modify information in a MySQL database when a user clicks on a hyperlink? I'm developing a voting application. It enables users to save questions for immediate use or later use. When the user is viewing their created questions, t ...

Interactive menu backdrop determined by div element

I am working on a website with a menu structured like the following: Home -- Work -- Pricing -- Contact Us -- About This website uses a one-page layout and has enabled Scrollspy on Bootstrap. I need to make the active menu background dynamic depending o ...

Customize your Bootstrap tabs with a unique border design

I am currently working on a wizard project where the header design is inspired by the image below. I am utilizing Bootstrap-4 tabs components and the :after pseudo element method on the li element to achieve this effect. However, I am facing a challenge in ...