Chrome and Firefox display varying heights for 'div' elements

My table has cells with div elements of varying content, resulting in different heights. You can see an example of this in the following fiddle:

https://jsfiddle.net/6btarubL/2/

The code is simple:

HTML

<table>
  <tr>
    <td>
      <div style="background-color: orange">
        DIV
      </div>
    </td>
    <td>
      <div style="background-color: aqua">
        Line 1<br>
        Line 2
      </div>
    </td>
    <td>
      <div style="background-color: #fac">
        10<br>
        20<br>
        30<br>
      </div>
    </td>
  </tr>
   <tr>
    <td>
      <div style="background-color: #8f5">
        DIV
      </div>
    </td>
    <td>
      <div style="background-color: #cb1">
        Line 2.1<br>
        Line 2.2
      </div>
    </td>
    <td>
      <div style="background-color: #eda">
        10<br>
        20<br>
        30<br>
      </div>
    </td>
  </tr>
</table>

CSS

tr {
  height: 100%;
}

td {
  vertical-align: top;
  min-width: 150px;
  height: 100%;
}

td div {
  height: 100%;
}

I want the divs inside the cells to take up all the space and appear uniform. Firefox achieves this, as shown in its rendering:

https://i.sstatic.net/kMWGd.png

However, Chrome does not comply with the height : 100% property for the divs, resulting in a different rendering:

https://i.sstatic.net/A4rcF.png

A curious observation is that Chrome used to render it like Firefox until I updated to version 63 (I had version 59 before).

Any suggestions? Thank you!

Answer №1

Please update the CSS code below and then retest it in Chrome:

td {
  vertical-align: top;
  min-width: 150px;
  height:1;
} 

Answer №2

Modify the HTML as shown below

<table>
          <tr>
            <td>
              <div style="background-color: orange">
                Box
               <br>
               <br>
               <br>
              </div>
            </td>
            <td>
              <div style="background-color: aqua">
                Line 1<br>
                Line 2<br>
               <br>
              </div>
            </td>
            <td>
              <div style="background-color: #fac">
                10<br>
                20<br>
                30<br>
              </div>
            </td>
          </tr>
           <tr>
            <td>
              <div style="background-color: #8f5">
                Box
               <br>
               <br>
               <br>
              </div>
            </td>
            <td>
              <div style="background-color: #cb1">
                Line 2.1<br>
                Line 2.2<br>
               <br>
              </div>
            </td>
            <td>
              <divzstyle="background-color: #eda">
                10<br>
                20<br>
                30<br>
              </div>
            </td>
          </tr>
        </table>

Answer №3

The resolution was found in this CSS:

<!-- THIS CODE DOESN'T WORK -->
tr {
  display : flex;
  height: 100%;
}

td {
  vertical-align: top;
  min-width: 150px;
  height: 1;   
}

td div {
  height: 100%;
}

I'm back to square one. As mentioned by @3rdthemagical, the display : flex on <tr> is causing layout issues and misalignment of columns. So, I conducted another test and here are the findings:

CSS WORKING IN CHROME:

tr {
  height: 100%;
}

td {
  height: 1px;
}

div {
  height: 100%;
  background-color: aqua;
}

Sample result:

https://i.sstatic.net/3ORKA.png

The code above appears differently in Firefox:

https://i.sstatic.net/9sCm5.png

CSS WORKING IN FIREFOX:

tr {
  height: 100%;
}

td {
  height: 100%;   /* <---------------- */
}

div {
  height: 100%;
  background-color: aqua;
}

However, Chrome presents a problem which initiated this question, resulting in the following output:

https://i.sstatic.net/os4wc.png

Who is correct? Chrome or Firefox? Is there no universally compatible solution for this?

I will continue my investigation...

Answer №4

To achieve the desired layout, utilize the power of display flex

Check out this jsfiddle for a live example

Here is the CSS code:

tr {
  height: 100%;
  display: flex;
}

td {
  vertical-align: top;
  min-width: 150px;
}

td div {
  height: 100%;
}

By using flex properties, you can easily center elements, adjust alignment vertically, change the order of items, and more.

I have tested this code in Mozilla Firefox; if needed, consider adding prefixes for wider browser compatibility:

  display: -webkit-box;
  display: -webkit-flex;
  display: -moz-box;
  display: -ms-flexbox;
  display: flex;

Answer №5

After struggling with finding a solution, I finally resorted to using CSS conditionals to load different styles based on the user's browser. You can find a detailed explanation of my approach in this question:

Implementing browser-specific CSS rules in an Angular 4 component

Cheers,

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 is the best way to compare a LatLng object with another one that is stored in an array?

Just starting out with JavaScript and decided to work on building apps using Google Maps. However, I've come across a puzzling issue. Take a look at the code snippet below. <html> <head> <script src = "http://maps.googleapis.com/maps/ ...

The app is opening the index.html file instead of the expected index.jsx file

After creating a page with React.jsx, I encountered an issue where my page was initially opening index.jsx upon running npm start. However, when I deleted and then restored the index.html file to "public", the page started opening index.html instead. This ...

Guide on utilizing the h function in Vue3 for seamless binding and passing of properties and events from parent to child components

Utilizing Vue3 and naive ui for front-end development has been a challenge for me as I primarily focus on back-end development and lack expertise in front-end technologies. To enhance user interaction, I incorporated naive ui’s BasicTable along with an ...

Ipad air experiencing difficulty displaying webapp correctly

Looking for some assistance with a webapp I've created. Your help and advice would be greatly appreciated. The app is designed to work at 1024px x 768px and functions perfectly on the ipad 4th gen in landscape mode. However, when viewed on an ipad ai ...

The datepicker in Angular Material refuses to open when used within a modal dialog box

I successfully integrated an angular material 2 date-picker into a bootstrap modal form: <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title">{{title}}</h ...

Issues with form inputs alignment in Bootstrap 4 styling

Check out this sample jsFiddle I created, using the html directly from my website. The css for bootstrap 4 is included, which I compiled using sass in addition to my custom css. Everything seems to align perfectly on all screen sizes, except for small dis ...

Tips for inserting an HTML table into a div element using JQuery/JavaScript

I currently have a navigation bar with only two items. While I may potentially add more items in the future, for now I am content with just these two. Upon opening the page, my goal is to display the content of the first item in the navigation bar. Each it ...

Effortlessly connecting Angular with forms

Check out this jsfiddle demo: https://jsfiddle.net/zpufky7u/1/ All the forms on my site were functioning correctly until suddenly angular started binding them all with class="ng-pristine ng-valid" Could this be due to a setting or something else causing ...

Having trouble getting the div to center using margin: auto?

I have a fixed div that spans 100% of the screen width, with another div inside it that has a set width in pixels. Despite having a width: auto, it seems to be aligned to the left: http://jsfiddle.net/jv87N I am puzzled as to why margin: 0px auto; is not ...

Personalized Styling: Transform the Color of the Active Navigation Pill

I am working with Pill tabs that are assigned the color #d7e5ea. The goal is to change the color of the active pill tab to #83a8b5 while keeping the inactive ones at #d7e5ea. Is there a specific custom CSS code that can be used to achieve this color chang ...

Creating a responsive btn-group for all screen sizes

I have a large collection of buttons that I need to organize into groups on my website. Currently, the design is not displaying them neatly in rows as I would like. I am using bootstrap 4. <div class="btn-group" data-toggle="buttons"> < ...

Is it possible to dynamically set the width of a CSS box?

When working on a Django project, we often provide data in the views.py file and then access it in an HTML template using Jinja templating {{...}}. However, I have a specific requirement where I need to use this data as the pixel size for the width of a bo ...

A picture placed side by side with a list

Could someone please help me figure out what I'm doing incorrectly? <div class="row"> <ul class='list-group .col-md-6'> <li>1</li><li>1</li><li>1</li> </ul> <div> ...

Transitioning jQuery .load and the usage of sorttable.js for sorting data

My jQuery code snippet is as follows: $("#loadBtn").click(function(){ $('#div1').delay(200).slideUp('slow') .load ('page2.php #div2').hide().delay(300).slideDown('slow'); return false; ...

The IDs and classes of HTML elements

I have two different implementations of a livechat script. On my sandbox site, the livechat is fixed to the bottom right of the page and scrolls with the window. However, on my live site (where this specific code comes from), it is attached to the footer. ...

Encountering a problem with Selenium in the Chrome Browser when utilizing a Docker image and RemoteWebDriver on macOS Big Sur - receiving an unfamiliar error message: "DevToolsActivePort file is

Attempting to execute a basic test by launching the Chrome browser on Selenium 3.141.59 Docker image on macOS v11.2.2 with the provided code: package testProject; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.WebD ...

Seeking assistance in creating custom tabs for integration with a jQuery tabs plugin

Attempting to navigate the world of CSS as a newbie, I find myself struggling with creating tabs. Our current tab setup can be viewed here, but unfortunately, these tabs are created using an unattractive <table> tag. Below is the code responsible fo ...

Using require to access an Immediately Invoked Function Expression variable from another file in Node.js

File 1 - Monitor.js var MONITOR = (function () { // Code for Monitoring return { doThing: function() { doThing(); } }; })(); File 2 - Test.js var monitor = require('../public/js/monitor.js'); I am trying to access the doThing() funct ...

unable to convert event.target to a string

Trying to pinpoint the element being clicked by the user, I am utilizing the Event Object target. $(document).click(function (e) { var str = e.target.toString(); console.log(str); if (str.indexOf("some class or id") >= 0) { //do ...

Detecting the preferential usage of -webkit-calc instead of calc through JavaScript feature detection

While it's commonly advised to use feature detection over browser detection in JavaScript, sometimes specific scenarios call for the latter. An example of this can be seen with jQuery 1.9's removal of $.browser. Despite the general recommendatio ...