Chrome distorts the display:table when zoomed in

Consider this CSS snippet:

.table {
    display:table;
}
.table-row {
    display: table-row;
}
.table-cell {
    display: table-cell;
}

Now, let's add some HTML to go along with it:

<div class="table">
    <div class="table-row">
        <div class="table-cell">
            <label>Label One</label>
        </div>
        <div class="table-cell">
            <input type="text">
        </div>
    </div>
    ...
</div>

At 100% zoom level, everything looks fine. But when we zoom in to 400%, then reset to 100%, things get messy.

If you want to see an example, check out this fiddle.

Unfortunately, Chrome versions 28, 29, and 30 seem to have trouble handling the spacing with this setup. Firefox, Safari, Opera are unaffected, and surprisingly Internet Explorer does not cause issues either.

Other than ditching

display:table/table-row/table-cell
, is there a way to adjust the HTML/CSS so that Chrome respects spacing even after zooming?

Answer №1

The data you have appears to not be in a tabular format, but there are alternative methods to achieve the same results. Instead of using a table structure like this:

<div class="table-row">
    <div class="table-cell">
        <label>Label Three pushes this table</label>
    </div>
    <div class="table-cell">
        <input type="text">
    </div>
</div>

You can try using a list with spans for alignment, like so:

<ul>
    <li>
        <label>Hello</label>
        <input type="text" />
    </li>
    <li>
        <label>Hello</label>
        <input type="text" />
    </li>
    <!-- Add more li elements here as needed -->
</ul>

For better control over spacing, you can utilize the following CSS:

label {
    display: inline-block;
    margin-right: 5px;
}

ul li {
    margin-top: 10px;
}

If you prefer a tabular layout, consider using the table element:

<div class="table-row">
    <div class="table-cell">
        <label>Label Two</label>
    </div>
    <div class="table-cell">
        <input type="text">
    </div>
</div>

This can be simplified to:

<tr>
  <td></td>
</tr>

Some optimizations for your CSS include targeting specific elements within the table:

.table > div {
   /* Remove the need for all classes named table-row */
}

.table > div > div {
   /* Remove the necessity of table-cell classes for styling */
}

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

Generating output into several spans of identical class using JavaScript with compatibility for IE8

Trying to make sense of GetElementsbyClassName function here. My goal is to output the value of an input field, identified by ID, to multiple spans that share a common class on click. I had it working fine with ElementId, but now I need to repeat the user ...

Error: ShowModalEdituser has not been defined

When implementing this code to display a modal in ASP.NET Core 5, I encountered the following error: Uncaught ReferenceError: ShowModalEdituser is not defined at HTMLButtonElement.onclick(). As a result, the modal does not appear. How can I resolve this er ...

Tips and tricks for locating the xpath of a header title using Selenium Webdriver and Java

Looking to locate the xpath of a header title that is only accessible through the 'inspect element' tab with its class and text content provided. The objective is to create an if statement to verify whether the page's title matches my desir ...

Generate and delete dynamic iFrames through variable manipulation

I'm currently developing a landing page specifically for our pilots to conveniently access weather information before taking off. However, due to the limitations posed by our computer security measures, I can only utilize iframes to obtain the necessa ...

What steps do I need to take in order to successfully make a checkbox?

I am attempting to use Angularjs to set a checkbox to true. When saved, it should store an integer value (1 or 0) in my field. Below is the code snippet for the view: <input type="checkbox" ng-model="lis.SMSPromotion" id="SMSPromotion" ng-init="checke ...

A single click causes the entire row of cards to extend seamlessly

The cards on this tab were generated using a loop and the data is sourced from a database. When I click on the "Show More" button, the entire visible column expands along with it. The expansion does not reveal the content immediately; instead, the content ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

What measures are in place to prevent content from being copied on this website?

I'm facing an issue with my website where users are unable to select and copy text using their mouse. The site is hand-coded in PHP and I've tested it on multiple browsers, but the problem persists. I understand that some people may want to preve ...

Encountering an inexplicable "undefined" error in HTML after receiving an

(apologies for any misspelled words) Hey everyone, I hope you're having a great time. This is my first experience with ajax, and I'm trying to incorporate some elements (messages sent and received) into HTML using ajax. However, all I see is an u ...

transferring background-image in html between elements

Imagine having a three-level hierarchy HTML code structured like this: <section> <div id="outer"> <div id="inner"> </div> </div> </section> If we set background-image:someImage.jpg to the section, and backg ...

Learn how to enable or disable a specific JavaScript script by clicking on a toggle button

I am currently exploring a new functionality for my basic tool that will introduce a "guided" approach to using it. The concept is simple: when a user selects a button, it will trigger the enablement and disablement of other buttons. However, I have real ...

My project is experiencing issues with the execution of JavaScript codes

Greetings, I'm having trouble with my JavaScript codes. The following code works perfectly: function Choice() { var box = document.getElementById('searchh'); if (!count) { var count = 0; } box.onclick = function () ...

Stop the entire page from scrolling in Next JS, while still enabling individual components to scroll

My ultimate goal is to have a fixed, sticky menu bar at the top of my app, followed by a div/component that houses the remaining content and does not scroll itself, while still allowing sub-components the ability to scroll when necessary. I plan to build t ...

Show the Canvas element at the back of the DIV

This particular question requires a clear explanation. My goal is to have the canvas act as a background element on the page, while the main content of the page starts in its usual position. I attempted using separate DIVs with their own Z-index values, bu ...

Switch the color (make it gray) of the selected tab in the navigation bar

<!-- Customizing the Navbar --> <nav class="navbar navbar-expand-sm bg-primary navbar-dark"> <a class="navbar-brand" href="<?php echo base_url('Controller_dashboard'); ?>"><strong>StuFAP MS</strong></a> ...

Sorting through various data inputs in one JSON file

I have a JSON file containing an array of objects: obj= [{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"t ...

Show images aligned in the center with proper positioning

img { vertical-align: middle; } .right { ??? } <img align='right' class='right' src='images/online_icon.png' border="0" width=8/> I am trying to position images on the right side while keeping them vertically aligned ...

Retrieve the input value closest to the selected row

I need to extract the price and currency value of a checked row containing a checkbox. The price is specified in a text box while the currency is selected from a dropdown menu. $(document).ready(function() { $('#test').click(function(){ ...

Parallax effect overlay for DIV

Planning to give my website a makeover and I'm thinking of adding some parallax effects to make it more engaging. My idea is to have 3 boxes overlapping each other (with the 2nd and 3rd box appearing blurry). These boxes would be placed at the top of ...

Issue with Bootstrap 4 progress bar malfunctioning in popover due to CSS property restrictions within the popover container

The following code functions correctly in the body area: <div class="progress" style="height: 25px;"> <div class="progress-bar" style="width: 30%;" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"> </div> & ...