Troubleshooting spacing problems in IE7 when using floating DIVs with left and right margins

I am trying to design columns with specific widths and margins in percentages that can fit inside any container with a dynamic width.

view example here

<div class="gridFluid">
    <div class="col-1-4"></div>
    <div class="col-1-4"></div>
    <div class="col-1-4"></div>
    <div class="col-1-4"></div>
</div>

 * {
     margin: 0;
     padding: 0;
 }
 body {
     font-size: 1%
 }
 .gridFluid {
     width: 960px;
     display: table;
     background: #eee;
     font-size: 0px;
     overflow: auto;
     zoom: 1;
 }
 .col-1-4 {
     background: #ddd;
     height: 200px;
     width: 23%;
     display: table-cell;
     *display: inline;
     zoom:1;
     margin-left: 1%;
     margin-right: 1%;
     float: left;
 }

This layout works perfectly everywhere except in IE7, where the last column does not fit properly in a single line. This issue may be due to unnecessary spacing between DIVs other than the margin.

Using different widths or margins for IE7 is not an ideal solution. I am seeking a better way to address this problem without compromising the overall design integrity.

It seems to be a common issue with IE7, as I have come across several related problems while researching for a solution but have not found a suitable resolution yet.

Answer №1

Let's perform some rapid calculations based on your CSS specifications.

You've indicated that each column should occupy 23% of the container width. Therefore, the width of each column would be:

.23 * 960 = 220.8

This means that each column should have a width of 220.8 pixels.

You've also mentioned that you want the margins to be 1% wide.

.01 * 960 = 9.6

Thus, each margin should be 9.6 pixels wide.

However, there are partial pixels involved. How do you handle .8 or .6 of a pixel? Rounding is necessary, but should you round up or down? If you round up, you'll end up with columns sized at 221 pixels each.

221 * 4 = 884

Therefore, the total width of the columns is estimated to be 884 pixels.

What about the margins?

8 * 10 = 80

This translates to an estimated total width of 80 pixels for the margins.

Now, let's combine these values.

80 + 884 = 964

It seems we have 4 extra pixels here. To fit within the confines of the 960px wide box, it's advisable to shift the content down a line.

Your columns are experiencing this downward push due to these adjustments. For more information, refer to: http://ejohn.org/blog/sub-pixel-problems-in-css/

Answer №2

To enhance your css, consider making a slight modification...

Adjustment:-

.col-1-4 {
     width: 23%;     
 }

Modify to:-

.col-1-4 {
     *width: 22.9%; 
     width: 23%;    
 }

Answer №3

What if we use nested divs? This should help resolve the issue.

 .col-1-4 {
     position:relative;
     background: #eee;
     height: 200px;
     width: 25%;
    /*******************************/
    /* Avoid using unnecessary properties */
     display: table-cell;
     *display: inline;
    /*******************************/
     zoom:1;
     float: left;
 }
 .col-1-4>div {
     background: #ddd;
     position:absolute;
     left:4%;
     right:4%;  /* 100/25 = 4 */
     top:0;
     bottom:0;
 }

View working example on Fiddle

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

Tips for avoiding Bootstrap collapse overflow within a container that has overflow-y-scroll

I'm currently facing an issue with a container that has the overflow-y-scroll CSS property. Inside this container, there's a Bootstrap collapse button that expands to show more content when clicked. The problem arises when the expanded content ov ...

Adjust the DOM based on the output of the function

I'm currently working on creating a list where only one element can be active at a time. The state is updating correctly, but I'm facing an issue with the isActive function. It only activates initially and doesn't trigger when the state chan ...

Unique menu design featuring dynamic floating text and creatively asymmetrical sides

I need help creating a customized menu for my website that resembles the design in this image. https://i.sstatic.net/07Ezu.png The menu layout should consist of three main sections as shown by the dotted boxes: a centered logo, a left side with menu items ...

Having trouble with JavaScript/JQuery not functioning properly in HTML content loaded using the load() method

My goal is to load an input form from a separate file called new_machine.php into my index.php. This form includes an input with a dropdown that retrieves options from a MySQL database and displays them as anchors. The issue arises when I attempt to manipu ...

Troubleshooting CSS3 pulse animation failure in Internet Explorer and Firefox

My animated background is looping infinitely and working perfectly in Chrome and Safari. However, I'm having trouble getting it to work in IE and FF. I've tried looking at other people's questions on this topic but still can't figure it ...

Struggling to position a div below another div within a flex box layout

https://i.sstatic.net/8vZSW.jpg When trying to make the Information & advice header appear above the other div elements, I encountered an issue with flexbox. Despite setting the container div to have a flex direction of column, the header div continue ...

Tips for keeping an icon aligned in the middle of a responsive square container

Currently, I am facing an issue with a div element that is supposed to be a square and remain so regardless of the device being used. My challenge lies in centering a FontAwesome icon within this square across all screen sizes. Despite my efforts, the desi ...

A guide to customizing the label color in Material-UI's <TextField/> component

How do I change the text color of the "email" label to match the border color? Below is the provided code: import React, { Component } from "react"; import { Icon } from "semantic-ui-react"; import { Divider } from "semantic-ui-react"; import { TextField ...

Reformat an input number by substituting commas with periods

Here's the code I'm working with: <input type="number" tabindex="3" placeholder="Item Price" step="0.01" min="0.10" max="999.99"> An example value inside this input is 1,95. I need to replace the comma with a dot. Can this be done using ...

Is it possible to close the menu by clicking outside a div or letting it disappear on mouseout after a set period of time?

When visiting a website, you may notice menus that display sub-menus when hovered over. These menus and sub-menus are created using div elements, with the sub-menus hidden initially using style.display = none; The issue arises when a sub-menu is opened an ...

The code `$(body).css({'background-image':'url'}) is not functioning properly

Is it safe to assume that the .css() method cannot be applied to the body tag? Since it seems to work fine when used on $("#div")... ...

The CSS transition feature does not seem to be functioning properly when it comes to displaying

In my Next.js application, I am using a card component with a "read more" link that should expand the card when clicked. To achieve this behavior, I integrated the "react-show-more" library from https://github.com/One-com/react-show-more. I tried to add ...

"Perpetual access to color selection through the input type

Can you assist me? I am currently using the input type color and looking to have the color picker always visible without requiring a click. Is there a way to achieve this through html, css, javascript/jquery, or any other method? Thank you in advance. I ...

Unable to display remote image source in PhoneGap

Trying to accomplish a simple task here. I aim to showcase an image hosted on a remote server in my phonegap app, but despite my best efforts, I haven't been successful. • Experimented with using an absolute file path in the image tag within the HT ...

The values in my array are causing it to output NAN

I'm currently working on a program that aims to combine a variable number of one-row matrices with varying lengths. The goal is to add the elements of each matrix together, where element one of array one adds to element one of array two, and so forth. ...

Angular Collapsible Panel showcasing brief summary

I am struggling to implement an accordion feature in Angular that displays a brief description of the content initially, and when clicked on, reveals the full description. I need to truncate the content and display it in the header. Despite my attempts, I ...

"Stop" and "start" a loop in AngularJS

Feeling a bit lost on how to articulate this inquiry, or even where to start looking for answers. I have a dynamic photo/text feed populating an array, meaning my page is constantly being updated with new information. The influx of data is happening at a ...

Ensuring my website doesn't load within an iframe using PHP

I attempted to prevent my site from loading in other locations, but unfortunately, my efforts were unsuccessful even after using the following code. <?php header(X-Frame-Options: allow-from https://example.com); header(X-Frame-Options: deny); ?> Is ...

What steps can I take to prompt this function to modify the value of my input?

After recently delving into the world of JavaScript, I decided to create a background color generator that randomly changes when a button is clicked. This simple project involves two input fields (color1 & color2) which receive random values upon clicking ...

Prevent anchor jumping caused by popstate event in Safari

This situation is really testing my patience. When navigating within the same page using anchors, the browser automatically takes you back/forward to the location of that link in your history when popstate is triggered. One might think that you could prev ...