473,761 Members | 7,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE8 display: table-cell and max-width bug?

Atli
5,058 Recognized Expert Expert
Hi.

I'm setting up a small photo-album-type thing, where I use PHP to set up a list of images for visitors to click through.
That's all simple enough.

However, I'm having a weird bug in IE8.

Because the images can all be of different sizes (nothing I can do about that... outside my control), I use a CSS trick to get them all centered both vertically and horizontally, and scaled down to a proper size.

Basically, I put the image tag inside two div tags, the first one to align the divs horizontally, and the second to align the image both horizontally and vertically.
Then the image tag scales down images that are to large using the max-height and max-width styles.

That all looks like this:
(Added the borders to see the exact position of the divs)
Expand|Select|Wrap|Line Numbers
  1. #GalleryPreview {
  2.     width : 400px;
  3.     height : 290px;
  4.     margin : 0 auto;
  5.     border : 1px solid #0000ff; /* For debuging */
  6. }
  7. #GalleryPreview_VerticalFix {
  8.     width: 400px;
  9.     height : 290px;
  10.     display : table-cell;
  11.     vertical-align : middle;
  12.     text-align : center;
  13.     border : 1px solid #00ff00; /* For debuging */
  14. }
  15. #GalleryPreview img {
  16.     max-width : 400px;
  17.     max-height : 290px;
  18. }
Expand|Select|Wrap|Line Numbers
  1. <div id="GalleryPreview">
  2.     <div id="GalleryPreview_VerticalFix">
  3.         <img src="PHP Generated" alt="Image Preview" />
  4.     </div>
  5. </div>
This works in all the standard supporting browsers. Everything is scaled down and centered perfectly. IE7 fails to do the vertical alignment, but that's good enough for IE.

IE8, on the other hand, does something much worse.

For images that scale down to less then the set max-width, this works perfectly to. It centers them both vertically and horizontally.

But when images scale down to exactly the max-width, the table-cell appears to forget it was scaled down, expanding itself until it reaches the width of the original image size. But it still centers the image correctly... just way out of place.
(See the images I attached. One is from Firefox, the other IE8)

I'm thinking this must be a bug in IE (shocking, I know). I mean, the image is scaled, but it's original width is being used by it's parent, which is not the case with the height.
Either this was the intended behavior and the height is bugged, or it's not and the width is.
(Edit: I found this bug report. Seems to be it)

In any case, does anybody know a workaround, or another method to center the images?
I'll keep looking, hopefully find something before I just drop IE support altogether :)

Thanks,
- Atli
Attached Images
File Type: jpg img_bug_ie8.jpg (15.9 KB, 4653 views)
File Type: jpg img_bug_firefox.jpg (13.8 KB, 3528 views)
Jun 9 '09 #1
22 60818
AsraiLight
3 New Member
Have you found a solution for this problem? I am having the same trouble, but I can't seem to fix it. Any help/insight you can provide would be much appreciated. :)
Jun 25 '09 #2
Atli
5,058 Recognized Expert Expert
I'm sorry to say that I did not find any way to work around this.

The cause of this is a bug in IE8's awesome new standards-supporting rendering engine (sarcasm intended) which, until fixed (if ever), will cause table-cell elements to scale out of proportion like that.

I suppose a JavaScript solution would be possible.
This only appears to happen when the contents (in my case, an image) with max-width set scales down to exactly the value specified.
If you were to catch those cases with JavaScript and shrink the image further, it should, in theory, circumvent the problem.
Or you could just have JavaScript dynamically scale the image, skipping the max-width scenario altogether.

I haven't tested this (I've abandoned my Windows partitions since I posted this), so I can't say for sure, but it at least sounds plausible.
Jun 26 '09 #3
drhowarddrfine
7,435 Recognized Expert Expert
Have fun with these. Especially the last one:

The following regressions are present in IE 8:

* Min-width on new block formatting context beside a float is sometimes treated as width.
* Percentage width floats cause justified text to move.
* Max-width fails on floats with auto overflow.
* Scrollbar height is added onto max-height instead of subtracted from it.
* Max-height acts as height on elements with scrollbars.
* Combining max-height, float and overflow:scroll will cause the entire page to disappear.
Jun 26 '09 #4
AsraiLight
3 New Member
Well, I think I figured it out! ...at least for my specific problem, which has to do with table cells. I noticed that when I tried using divs, the resize problem didn't happen...but using tables screwed up the formatting of the cells. (Normally I wouldn't use tables, but I needed a fixed grid-like layout, and divs just don't cut it for that.)

Anyway, I added the style "table-layout: fixed;" to my table's stylesheet, and it works in both IE 8 and IE 7. Not sure if this might help your div problem, but at least it's something...
Jun 26 '09 #5
drhowarddrfine
7,435 Recognized Expert Expert
@AsraiLight
Oh? I normally think these people are incompetent but they do a pretty good job doing that without tables.
Jun 26 '09 #6
AsraiLight
3 New Member
Of course...becaus e it's not a grid. Your example is made to be more fluid. I've tried doing images of differing sizes with captions in boxes which are the same size and lined up side-by-side, but I can't get it to work across the board. Different instances need constant tweaking to get them to look right, which I'm not willing to do. The tables just work.

Plus, I'm not using them for my site layout, just for the content, which isn't going to be redesigned...so it doesn't really matter.
Jun 26 '09 #7
aim1900
1 New Member
@AsraiLight
Thanks, man, it does work for divs. I simply added the "table-layout: fixed;" to my outter div (display: table;) and set its width to the max-width of inner img (previous I didn't set this as in firefox the original trick works perfect). This is necessary otherwise the fixed layout of table won't work. Here is what w3c says to fixed layout:

Fixed table layout algorithm:
•The horizontal layout only depends on the table's width and the width of the columns, not the contents of the cells
Jul 10 '09 #8
drhowarddrfine
7,435 Recognized Expert Expert
@AsraiLight
I don't think MSN.com is fluid, and it is set up as a grid. I would show you a couple personal examples online but I won't (personal reasons) and they work in all browsers though, yes, IE always causes problems.
Jul 10 '09 #9
adinas
3 New Member
I was able to solve this by putting the content in the td in a div. For example:

Expand|Select|Wrap|Line Numbers
  1. <td style="width:100px"><div style="width:100px"><img src="..." style="max-width:100px" /></div></td>
Apr 1 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5632
by: Lachlan Hunt | last post by:
Hi, I was wondering if ::before and ::after pseudo-elements can apply to elements styled with the display: table-* properties. None of my tests worked in either Firefox or Opera, yet I could not find anywhere in either the CSS2.1, CSS3 Selectors or CSS3 Generated and Replaced Content Module specs that defines which elements these pseudo-elements actually apply to. Specifically, I was wondering if something like this were possible:
7
3623
by: Robert Blasius | last post by:
Hello, I've a problem displaying a header content in Internet Explorer. You can view the problem on www.robert-blasius.de The upperimage should be on the left of the middle "line" and the lower image should appear on the right. It works fine in Firefox, but not in IE 6.0. This is the css-code: div.titletable {
9
2636
by: wparrott | last post by:
I have a table called tblPayScales. It has 5 fields: numRecID - record ID txtCLASSCODE - a 1 or 2 letter text value (A, B, C, BD, L, LT, etc.) numPAYSTEP - a number value 0-49 numSALARY - a number value such as 36,246.00 numNEWSALARY - a number value derived from a user-defined percentage The table contains records for each CLASSCODE/PAYSTEP. Although there are 50 pay steps some have a value of 0 for numSALARY(no employee at that pay...
1
1527
letmeknow
by: letmeknow | last post by:
Do anybody know how to get the values from a display table
4
2046
letmeknow
by: letmeknow | last post by:
can we use hidden fields in display table
10
4617
by: removeps-groups | last post by:
How to display table and select next to each other? <html> <body> <table border=1 style="display:inline-table"> <tr><td>Hello1</td></tr> <tr><td>Hello2</td></tr> <tr><td>Hello3</td></tr> <tr><td>Hello4</td></tr> <tr><td>Hello5</td></tr>
1
2437
by: puT3 | last post by:
Hi, I'm trying to make a dynamic website using asp and javascript and access as my database. I'm wondering if the asp file able to display table from access where user can view and change the information in the table...
2
3550
by: KusoYumi | last post by:
Hi everyone, I have met a problem here regarding the display table. Let me explain my problem 1st. Assume that I want to display a list of data in a table, each page contains 10 records. So when I clicked on page no.2, it will showing records from 11 to 20. At this moment, I have click submit button to save the changes I did in page 2. So now my question is, after saved, it should be remain the page 2, but now it show "1, 2, 3, 4 " page 1 is...
2
1805
by: LuciaG | last post by:
Hello, I was trying to display table in vba form (excel 2003), but I was't successful. How can it be done? Thank you,
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.