In IE8, a border is applied to the max-width property when the width is set to

I'm attempting to design a box that adjusts in size according to the parent container, utilizing a mix of max-width and width:100%.

With this setup, the box's width is determined by the max-width property, ensuring it shrinks within its boundaries instead of overflowing when the parent container is too small.

While I have successfully implemented this in ie9, Firefox, and Chrome, I encountered an issue with IE8 standards mode where the padding seems to be included in the max-width calculation.

For example:


    <!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
    <style>
        #test
        {
            border: 1px blue solid;
            width: 100%;
            max-width: 210px;
            display: block;
            height: 30px;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }
    </style>

    <span id="test"></span>
</body>

This sets up a box that is a maximum of 210px wide on IE9, Firefox, and Chrome. However, in IE8, the added border causes the actual width to be 212px instead of the intended 210px. Removing the border reverts back to the desired width in IE8.

Although I tried changing the box-sizing property to content-box, there was no noticeable impact on how the box behaves.

Answer №1

Check out these resources to troubleshoot any compatibility issues with Internet Explorer:

(get respond.min.js) https://github.com/scottjehl/Respond

(download css3-mediaqueries.js) https://code.google.com/p/css3-mediaqueries-js/

Once you've downloaded the files, insert the following code into your <head> section:

<script type="text/javascript" src="respond.min.js"></script>

To ensure the entire box is responsive, try setting max-width to 100%. If you need to adjust the width of the box, maintain max-width at 100% while changing the regular width as needed.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
    <style>
        #test
        {
            border: 1px blue solid;
            width: 100%;
            max-width: 100%;
            display: block;
            height: 30px;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }
    </style>


    <span id="test"></span>
</body>

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

How do I simulate a checkbox click with jQuery based on the text included in its ID?

Below is a sample table with checkboxes: <table> <tr> <td><input id="aaa_1" type="checkbox" /></td> <td>1</td> </tr> <tr> <td><input id="aaa_2" type="checkbox" /></td> ...

A contact form overlaying a muted Google Maps view in an HTML website

Currently, I am in the process of developing a website that features a contact form. It would be great if I could incorporate Google Maps as a background, but with a greyed-out effect instead of a plain white page. After trying out a few solutions, I ende ...

Leveraging the Bootstrap 3 audio player, although displaying a standard HTML5 output

When trying to use the Bootstrap 3 player to display an audio player, I'm encountering an issue where the page only shows a default black HTML5 audio player output. Here is my current directory structure: miuse/ application/ bootstrap/ ...

Mobile Safari on iOS devices is known for its capability to overlay HTML5 <video> on top of everything

Although a similar question was asked 6 years ago without any answers, I am currently facing the same issue. Problem: The <video> tag in my Angular/Ionic application overlaps my image and two buttons in iOS Mobile Safari - no matter what I try! It ...

What is causing the data in the hierarchy table to be invisible?

I am attempting to build a hierarchical table using Vue.js as the foundation. However, I want the table to remain hidden with no data displayed. The issue seems to be within this section of code: <tr v-if="item.childrenVisible" v-for="chi ...

Every time I employ window.location, the Iframe becomes nested

I am experiencing an issue with my HTML structure: <html> <body> This is the container of the iframe <iframe src="/foo.html"> </iframe> </body> </html> (/foo.html) <html> <script type="text/javascript"> $( ...

Persistent button positioned at the bottom of the page, remaining visible even when scrolling to the very end of the content

I am looking to add a floating button that remains in the same position relative to the content until the window is scrolled to a certain point, after which it sticks to the end of the content. In simple terms, I want the element to act as 'relative& ...

Vertical centering menu adjustment

Can anyone help me with centering an image on my website? I've tried the following code: top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%); You can see what's happening on my site here: ...

Using PHP to calculate the total number of records within an HTML document

I am currently working on a PHP script to establish a connection with my MySQL database in order to retrieve the total number of users registered on my forum by counting the records in the table. The PHP script should display the total count above the sec ...

What can I do to resolve the problem with td border

Check out my website over at browsethewebclean.com I've come across a peculiar issue with the borders and background color of some nested tables on my page. It seems that the border is not aligning properly and the background color goes beyond the im ...

In Internet Explorer 7, a newline within a <pre> tag may cause display issues

Within my ASP.NET MVC 3 project, I am working with the following code: <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" ty ...

Transfer data between an HTML page and a PHP page hosted on separate locations using jQuery

Below is the code snippet I am currently working on: function send_data() { var a=$("#username").val(); var b=$("#password").val(); $.post("http://localhost/login/login.php", {uname: a, pswd: b}, function(data) { $("#result").html(data); }); ...

Tips for maintaining the height of the outer div consistent with that of the inner div

I am encountering an issue with an inner div that is used for overlay and set to a min-height property. Despite changes in the overlay's height, the height of the outer div remains unaffected. #outer { width: 70px; height: 70px; background-co ...

Tips for accessing the names of subdirectories and files on a website

If we have the URL, is it possible to access the names of the files within the parent directory? Similar to how we can do in DOS by using the command "DIR" to view the list of files inside a folder. For example, if we have a URL like , I am curious to kno ...

The cache feature seems to be malfunctioning, resulting in images having to be reloaded every time

I am working on a simple webpage at . The issue I'm encountering seems to be specific to Google Chrome - every time I reload the page, the images are reloaded as if there is no cache. I noticed that when checking the example on stackoverflow.com, the ...

What is the CSS technique for concealing the content of an ordered list item while retaining the marker?

In our order process, we utilize an ordered list to display the steps in sequence: <ol> <li>Products</li> <li class="active">Customer</li> <li>Payment</li> </ol> On desktop view, it appears a ...

Exploring the Excitement of PHP Regular Expressions (preg_replace)

Looking for assistance with a regex preg_replace function to clean up HTML content being submitted to my app's controller/model. The goal is to strip away unwanted HTML and convert specific elements into proprietary tags for the app. $postText = $_PO ...

Trigger keydown and click events to dynamically update images in Internet Explorer 7

There is a next button and an input field where users can enter the page number to jump to a specific page. Each page is represented by an image, like: <img src="http://someurl.com/1_1.emf" > // first page <img src="http://someurl.com/2_1.emf" ...

What is the best way to incorporate a style attribute into my EJS page content?

Having trouble with adding custom style. It seems to work, but there's an error displayed. Apologies for my poor english :( <div class="card card_applicant"> <div class="card_title" style="background-c ...

Strange CSS/browser storage glitch

UPDATE: JUST REALIZED THIS ISSUE IS ONLY OCCURRING ON FIREFOX, NOT CHROME ANOTHER UPDATE: Oddly enough, this problem only occurs locally. When I push it to GitHub, everything works fine. So strange. I suppose that means it's not a major issue. On my ...