Is the CSS3 bar chart flipped?

I'm currently developing a responsive bar chart, and everything seems to be going smoothly except for one issue - when viewing it in full screen, the bars appear to be flipped upside down. It's quite puzzling as all other elements such as text and styles are displaying correctly.

You can check out my HTML/CSS code here: https://codepen.io/janbe30/pen/YepGWB/ or simply view the code snippet below.

<h1>Bold Goal Measures</h1>

<figure>
  <figcaption>Modifiable Health Risks</figcaption>
  <ul class="chart">
    <li id="risk-1" class="bar" title="3.2">
      <div class="count">3.2</div>
      <div class="year">2012</div>
    </li>
    <li id="risk-2" class="bar" title="3.0">
      <div class="count">3.0</div>
      <div class="year">2013</div>
    </li>  
    <li id="risk-3" class="bar" title="3.0">
      <div class="count">3.0</div>
      <div class="year">2014</div>
    </li>
    <li id="risk-4" class="bar" title="2.93">
      <div class="count">2.93</div>
      <div class="year">2015</div>
    </li>
    <li id="risk-5" class="bar" title="2.96">
      <div class="count">2.96</div>
      <div class="year">2016</div>
    </li>
    <li id="risk-6" class="bar" title="3.2">
      <div class="count">3.2</div>
      <div class="year">2017</div>
    </li>
</figure>

body {
  font-family: Helvetica, sans-serif;
  color: rgb(65, 64, 66);
  font-size: 1rem;
}

.chart { 
  width: 100%; 
  clear: both;
  padding: 0;
}

.chart li {
  display: block;
  border-radius: 0.2em 0.2em 0 0;
  height: 3em;
  padding: 1.5em 0;
  position: relative;
  text-align: center;
  vertical align: bottom;
}

/* Styling of bars and text */
.chart .bar {
  background: linear-gradient(rgba( 65, 64, 66, .9), rgba(72,70,65, .9));
  margin: 0.3em;
}

.chart .bar:last-child {
  background: linear-gradient(rgba(78,131,23, .9), rgba(78,132,22, .9) 70%);
}

.chart .count {
  font-size: 1.8em;
  font-weight: bold;
  color: #fff
}

.chart .year {
  font-size: 0.9em;
  letter-spacing: 1px;
  opacity: .6;
  width: 100%;
  color: #fff;
}

/*******************************
===== Media Queries ===========
******************************/

@media (min-width:700px){
  .chart {
    height: 20em;
    margin: 0 auto -1em;
  }

  .chart li {
    display: inline-block;
    height: 25em;
    margin: 0 1% 0 0;
    width: 10% !important;
  }

  .chart .bar {
    margin: 0.3em 0.1em;
  }

  .chart .year {
    position: absolute;
    bottom: 1em;
  }
}

I've double-checked my code multiple times but still can't figure out this issue! Any help would be greatly appreciated. Thank you!

Answer №1

There seems to be a mistake in your CSS code.

Your current code:

vertical align: bottom

You should use a hyphen instead:

.chart li {
   vertical-align:bottom
}

Answer №2

It is recommended to include vertical-align: bottom; in the .bar class.

Pay attention to the dash between vertical and align

body {
  font-family: Helvetica, sans-serif;
  color: rgb(65, 64, 66);
  font-size: 1rem;
}

.chart {
  width: 100%;
  clear: both;
  padding: 0;
}

.chart li {
  display: block;
  border-radius: 0.2em 0.2em 0 0;
  height: 3em;
  padding: 1.5em 0;
  position: relative;
  text-align: center;
  vertical-align: bottom;
}


/* Styling of bars and text */

.chart .bar {
  background: linear-gradient(rgba( 65, 64, 66, .9), rgba(72, 70, 65, .9));
  margin: 0.3em;
  vertical-align: bottom;
}

.chart .bar:last-child {
  background: linear-gradient(rgba(78, 131, 23, .9), rgba(78, 132, 22, .9) 70%);
}

.chart .count {
  font-size: 1.8em;
  font-weight: bold;
  color: #fff
}

.chart .year {
  font-size: 0.9em;
  /*font-family: FSHumanaLight */
  letter-spacing: 1px;
  opacity: .6;
  width: 100%;
  color: #fff;
}


/* set widths for each bar based on percentages for each year 
.chart #risk-1, #risk-6 { width: 64%; }
.chart #risk-2, #risk-3 { width: 60%; }
.chart #risk-4 { width: 58.6%; }
.chart #risk-5 { width: 59.2%; }*/


/*******************************
===== Media Queries ===========
******************************/

@media (min-width:700px) {
  .chart {
    height: 20em;
    margin: 0 auto -1em;
  }
  .chart li {
    display: inline-block;
    height: 25em;
    margin: 0 1% 0 0;
    width: 10% !important;
  }
  .chart .bar {
    margin: 0.3em 0.1em;
  }
  .chart .year {
    position: absolute;
    bottom: 1em;
  }
  /* set widths for each bar based on percentages for each year */
  .chart #risk-1,
  #risk-6 {
    height: 64%;
  }
  .chart #risk-2,
  #risk-3 {
    height: 60%;
  }
  .chart #risk-4 {
    height: 58.6%;
  }
  .chart #risk-5 {
    height: 59.2%;
  }
}

@media (min-width: 1000px) {}
<h1>Bold Goal Measures</h1>

<figure>
  <!--<h2>Unhealthy Days</h2>-->
  <figcaption>Modifiable Health Risks</figcaption>
  <ul class="chart">
    <li id="risk-1" class="bar" title="3.2">
      <div class="count">3.2</div>
      <div class="year">2012</div>
    </li>
    <li id="risk-2" class="bar" title="3.0">
      <div class="count">3.0</div>
      <div class="year">2013</div>
    </li>
    <li id="risk-3" class="bar" title="3.0">
      <div class="count">3.0</div>
      <div class="year">2014</div>
    </li>
    <li id="risk-4" class="bar" title="2.93">
      <div class="count">2.93</div>
      <div class="year">2015</div>
    </li>
    <li id="risk-5" class="bar" title="2.96">
      <div class="count">2.96</div>
      <div class="year">2016</div>
    </li>
    <li id="risk-6" class="bar" title="3.2">
      <div class="count">3.2</div>
      <div class="year">2017</div>
    </li>
</figure>

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

Attempting to showcase extensive content based on the selection made in a drop-down menu

As a newcomer to anything beyond basic HTML, I am seeking guidance and assistance (preferably explained at a beginner level) for the following issue. If I have overlooked any crucial rules or concepts in my query, I apologize. I aim to have each selection ...

What steps can I take to prevent my menu items from overlapping in the mobile navigation menu?

I am currently working on creating a mobile menu, but I'm facing an issue where the menu items overlap when hovered over. Instead, I want the menu items to move downwards when hovered upon to prevent the text from overlapping. Below is the HTML code ...

An option instead of using a pop-up window

Currently, I have a PHP script and a small form that allows users to upload image files. The user can access this feature by clicking on a button on the parent HTML page, which opens up a Pop Up Window. I understand that not everyone is a fan of 'Pop ...

adding <script> elements directly before </body> tag produces unexpected results

While following a tutorial, the instructor recommended adding <script> tags right before the </body> to enhance user experience. This way, the script will run after the entire page content is loaded. After implementing the code block as sugges ...

Enhancing dynamic text boxes with jQuery by incorporating additional information

I've recently developed an interactive app that dynamically creates tables based on user input. The app includes a feature where you can specify the number of tables to generate and track the total count of tables added. Currently, I'm exploring ...

How is it that the magic table refuses to conform to CSS styling? This is truly sorcery!

My HTML table is as simple as it gets: <table class="dispdtab"> <tr> <td><b>Dealer: </b></td> <td>dealername</td> </tr> <t ...

Using TypeScript with React Bootstrap's <Col> component and setting the align attribute to 'center' can trigger a TS2322 warning

The React app I'm working on includes the code below. The Col component is imported from React-bootstrap <Col md={5} align="center"> This is a column </Col> When using Typescript, I received the following warning: ...

Using cascading style sheets to switch a page into editing mode

Is it possible to change the view of a page after clicking a button without using javascript, and instead relying solely on CSS? I want to display a page with information where users can click an edit button and make changes within the same view rather th ...

Instructions on making a Popup appear after a specified duration of mouse inactivity on a webpage

Hello, I am new to web development and could use some guidance on creating a popup window for users to enter their username and contact number. It should be able to store this information in a database and activate after the user has been idle for about 10 ...

When a button is undersized, the click event may not register

In my angular application, I have developed a directive for a tinyMCE editor. Upon setup, I have implemented two handlers: one for the blur event to hide the toolbar and another for the click event to show it. Additionally, I have created another directive ...

Issue with setting innerHTML of element in AngularJS app upon ng-click event

Look at this block of HTML: <div class="custom-select"> <div class="custom-select-placeholder"> <span id="placeholder-pages">Display all items</span> </div> <ul class="custom-select- ...

Transforming the MUI CircularProgress into a half circle shape

After utilizing CirculaProgress, I was able to achieve the following: https://i.sstatic.net/Y0Seo.png Is there a simple method to transform it into a semicircle like shown here? https://i.sstatic.net/D8bKu.png ...

Is there a way to create a scroll down and scroll up button that is located outside of the scroll box

A game designer challenged me to create a custom scrollbar with unique up and down button styles, as well as a custom-looking scrollbar. I wanted to achieve this without using the native browser scrollbar on Windows in Google Chrome. I attempted the follo ...

The function mysql_fetch_assoc is displaying absolutely nothing (neither null, nor 0, nor an empty string)

I'm encountering an issue with retrieving data from my $result variable. Everything works smoothly when there is one result, but if I try to check for a result and find none, the $array ends up empty. Running both commands below results in nothing bei ...

Tips for personalizing react-show-more text length with Material-UI Icons

In my SharePoint Framework webpart using React, I am currently utilizing the show more text controller. However, I am interested in replacing the "Show More" and "Show Less" string links with the ExpandMore and ExpandLess Material UI icons. Is there a way ...

Update the identifiers and titles for duplicated elements

On my form, users can input multiple delegate details. Here's a snippet of the HTML code: <div id="Delegate1" class="clonedInput"> <h4 id="reference" name="reference" class="heading-reference">Delegate #1</h4> ...

Using JQuery to dynamically set dropdown option values from a JSON object

I have an HTML code snippet: $.ajax({ type: "POST", url: "hanca/hanca_crud.php", dataType: 'json', data: { id_hanca: id_hanca, type: "detail_hanca" }, //detail_hanca success: function(data) { var teks = ""; $.each( ...

Challenges with arranging tables properly in React using Material UI

I am struggling to make this inner table span the full width and merge with all 8 columns. I have been unable to get the colspan attribute to work with material UI. The inner table is collapsible, which is working correctly, but the formatting of the table ...

A minuscule variation in width percentage due to a single pixel

I am experiencing an issue with a one pixel margin between two green colors on my website. I have been unable to locate the source of this problem. I am currently using display:inline-block. Here is the link to my website: ...

Arranging divs in a row using jQuery sortable technique

Greetings! I have been attempting to achieve horizontal sorting for two divs but have encountered a couple of issues. Firstly, the divs do not align correctly upon initial page load and secondly, while they can be dragged around, the sortable functionality ...