WebKit's percent-sized floats bug: are there any workarounds? - webkit

I'm experiencing what appears to be a bug in WebKit's rendering of floating elements' width when they have margins.
The following renders as one would expect in Firefox (3.6) and WebKit (Chromium 5.0):
<div style="width: 100%; background-color: green;">
<div style="background-color: red; float: left; width: 50%;">n</div>
<div style="background-color: red; float: left; width: 50%;">n</div>
<div style="clear: both;"></div>
</div>
That is to say, as a completely red box, with no green background showing.
Now try this:
<div style="width: 100%; background-color: green;">
<div style="background-color: red; float: left; width: 40%; margin-left: 10%;">n</div>
<div style="background-color: red; float: left; width: 50%;">n</div>
<div style="clear: both;"></div>
</div>
What is expected is the same as as before, except for 10% of the box on the left-hand side to be left green. This is what is seen on Firefox.
However, on WebKit browsers, one pixel of green is left on the right-hand side of the box: the floating elements no longer completely fill it up.
The problem appears to compound when more floats and margins are used, leaving a larger amount not filed up.
Is this a bug? A rounding error? It's certainly not what I expected. And more importantly, what can I do to get around it?
EDIT: After much searching I found that it is a reported bug; probably a rounding error as suspected: https://bugs.webkit.org/show_bug.cgi?id=5531
My most important question still stands: is there any way around the bug?

I suspect there is no magic workaround for this. Browsers interpret sizes in a mathematically different way. There is another question slightly related to this here, which is the particular problem I encountered. There is wider infomation here. I once read a great article explaining the problem very exactly, but I lost the bookmark. I'll try and find it again so I can post it here.
Essentially, different browsers round decimal pixel values differently. So, the short answer is you will never get an exact cross-browser solution as long as this differences exist. The particular problem I had was the one described in my first link: even without using percentage values (fixed pixel sizes), I encountered 2 "sides" between browsers, in which the vertical alignment of some elements would be different: Firefox and Internet Explorer, on the one side, and Opera, Chrome and Safari on the other.
Yet, this depended on the exact values of line-height and font-size I used, so sometimes I would get differences even between Firefox and IE, or other combination. Without using conditional CSS, I could only reduce the problem to those 2 groups, and then used conditional CSS to adjust the margins in Opera and Chrome.
So, to sum it up, as far as I know, I'm afraid you'll have to use conditional CSS. Cheers!

Perhaps something like this instead?
<div style="width: 100%;">
<div style="background-color: green; float: left; width: 10%;"></div>
<div style="background-color: red; float: left; width: 40%;">n</div>
<div style="background-color: red; float: left; width: 50%;">n</div>
<div style="clear: both;"></div>
</div>

Related

Whitespace on right side of website

I have a large amount of excess whitespace on the right hand side of my page (shown best when viewed on a mobile).
I believe this is caused by a margin-right somewhere but I can't seem to find the underlying issue.
Live link: http://185.123.96.102/~kidsdrum/moneynest.co.uk
I found two issues:
First, the #weeklyearningschartimage image should have a width of 100% so that it resizes with the parent. This should fix most of the extra white space on mobile.
After fixing that, you may notice that there is still a small bit of white space on the right side (even on desktop). This is because the .row elements are not wrapped in a .container-fluid
Check here for the proper grid HTML structure: http://getbootstrap.com/css/#grid
I imagine part of the problem is...
<div class="row richard">
.richard {
background-color: #232323;
color: white;
font-size: 130%;
padding: 2%; <-------- This applies to left and right as well
font-weight: bold;
}
You are adding padding to the left and right of a row which might give you overflow.
Yes, I see what's wrong in your website, see your code
<div class="row light-section">
<div class="col-sm-12">
<div class="col-sm-12 homepage-text">
the class homepage-text you have written max-with: 700px; please fix it with some %(80-90).

No text-shadow in IE10

I have a menu that has text-shadow applied to it, so that it blurres the links. It works as expected, except that in IE10 it completely hides the links.
Only when hovering over links they are revealed, because on hover text-shadow is removed.
Here is the applied code:
text-shadow: 0px 0px 3px #fff;
Also, here is the link...the menu is positioned bottom left part of the screen.
http://madebym.net/test/ractiv/index.html
There's a few possible reasons for this problem.
IE does not display text shadows the same as most brosers: IE shadows are more opaque for some reason. Then you would have to check the browser.
IE <=9:
filter:progid:DXImageTransform.Microsoft.DropShadow(color=#000000, offX=1, offY=1);
(Details: http://msdn.microsoft.com/en-us/library/ms532985%28v=vs.85%29.aspx)
(There also seems to be a filter named "blur" that might be more what you need. It's mentioned on the page.)
IE 10+:
text-shadow: 0px 0px 3px rgba(100%,100%,100%,0.8);
(Slightly transparent shadow to offset IE's shadow opacity. You could also reduce the size of the shadow and see what it does.)
Other browsers:
text-shadow: 0px 0px 3px #fff;
(Your normal code.)
The reason could also be that you made a shadow using an IE filter for previous IE versions, but forgot to NOT make it apply to IE 10, which supports normal shadows, resulting in the two effects stacking.
Sounds unlikely, but maybe there's a default value difference somewhere that affects this. Do you use a CSS reset?
Use This text-shadow: 0px 0px 3px 1px rgba(255,255,255,0.5).
It works here on IE10, Can you open the developer tools (F12) and make sure the rendering and document mode is set to IE10 and IE10 standards mode?
dstorey and Mark already pointed you to what is probably causing your problem. More specifically, you can search for a
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
or similar tag in the
<head>
section of your document and delete or conditional-comment it for IE versions lower than 10, since in case it is present it will prevent your document from rendering properly in IE 10.

Foundation 4 MVC4 Grid Issue

Some context:
Foundation 4.0.9 SaSS & Compass(Newbie), ASP.net MVC 4
Device: Screen
Chrome/26.0.1410.64
Can Also reproduce issue in User Agents: Firefox, Chrome, IE
Windows 7 64-bit
I have an issue where a single column appears centred/offset from the left edge of a containing row. What I expect is the column to be flush against the row's left edge?
<div class="row">
<div class="large-12 columns">
<div style="width: 500px; height: 500px; outline: solid black 1px"> </div>
</div>
</div>
Here is my fiddle http://jsfiddle.net/meanFiddler/aWNBp/
I am aware that Foundation includes classes to center columns such as large-centred although my example does not apply any directly and I could not see them being applied by external stylesheets under the chrome dev tools panel.
Is anybody aware of any in-depth tutorials of using Foundation 4?
Cheers
Remove the panel div and you should see your desired result. Panel adds margin and/or padding which, I assume, is what you don't want.
EDIT: I'm not sure what you're trying to do, but, it also might be unnecessary to set the width to 500px, as a 12-column grid will span the entire width by default (960px).

CSS font-size & <img> tag

Problem with font-size (line-height) affecting <img ... > elements
(at least in webkit / safari) It seems that extra space is applied under elements according to the font-size / line-height that affects the parent container.
in this example, the outer div is larger than the image (space is added under the image):
<div class="outer">
<img src="http://placehold.it/300x100" width="300" height="100">
</div>
but in this example no space is added:
<div class="outer">
<div style="width:300px; height:100px">
</div>
The bigger the font-size(line-height) on the outer div, the larger the space added. So the following CSS will fix the problem (but isn't a useful fix really):
.outer{
line-height: 0;
}
See a full demonstration of the problem here:
http://jsfiddle.net/mikkelbreum/wtKS2/
I'm sure this is a known 'problem', but I couldn't find a good treatment of the problem from my googling..
I would like to hear from others, if this is a well known problem (why would an image be treated as a text block with regards to line-height being added below it.) And is there an agreed upon way to handle this problem?
A way to solve it is adding the CSS property vertical-align:middle; or vertical-align:text-bottom; to the <img>. This will remove the space under the image.

CSS: Chrome and Safari seem to 'add' border to width, while IE, Firefox & Opera don't

I'm trying to achieve cross-browser consistency for my website.
It's about this page: http://www[insert-dot-here]geld[insert-dash-here]surfen[insert-dot-here]nl/uitbetalingen.html (please note that I prefer this URL not to be made crawlable for seo-bots)
If you view this page in IE, Firefox or Opera, everything is fine, but in Chrome and Safari the tables are a little out of line (as you'll probably clearly notice).
What seems to be the problem?
It appears to me that in Chrome and Safari the left and right border (2px) in total are added to the set table width, while in the other browsers the border is considered part of the width.
The (most) relevant CSS-lines are the following ones (from the table.css file, also available through the page's source file):
table.uitbetaling {
margin: 11px 18px 10px 19px;
border: 1px solid #8ccaee;
width: 498px;
padding: 0;
}
table.uitbetaling img, table.uitbetaling td {
margin: 0;
border: 0;
padding: 0;
width: 496px;
}
table.uitbetaling tr {
margin: 0;
border: 0;
padding: 0 1px 0 0;
}
So basically I have used a table-structure to organize images, like this: (the class of the table is uitbetaling)
<table>
<tr><td><img /></td></tr>
<tr><td><img /></td></tr>
...
<tr><td><img /></td></tr>
</table>
If, here, I set the width of table.uitbetaling and table.uitbetaling img, table.uitbetaling td to the same value (e.g. both 496 or 498), the "problem" in Chrome and Safari is solved, however in Firefox the right side border is than blank. Because the right-side border can't "fit" in anymore. img and td must be at least 2px more narrow than table.uitbetaling for the right-border be visible in Firefox.
Is there any way to solve this?
Nowadays you should be using the HTML5 doctype, if you're having issues about borders adding themselves to the element's width look up the CSS style: box-sizing
border-box - include border width/height and padding width/height or basically the width you set includes the borders/padding
content-box - the width you set on the element is only the content area, this does not include padding or borders
There is also padding-box which I don't use, usually the above two are enough.
Now sometimes, I think IE8 uses a different box-sizing than Chrome/FF etc, this is why sometimes you have issues. You can always debug and check what the box-sizing is set to.
Note: if you don't have the DOCTYPE then you're in quirks mode, and IE differs WILDLY from Chrome/FF on the box-sizing/box model - and that's your problem right there
segment your code into its simplest elements and test them on each browser. When you find the differences you can use different methods of browser detection to subtly alter the code for each instance. With that said... if you do not want to go stark raving mad, and CSS will do that more then anything in programming let the pixel go if you can.
To be safe, I usually open a table in this way:
<table cellspacing="0" cellpadding="0">
It is "old" HTML, but at least it forces coherency along browsers, and then I apply CSS as needed.
I'd checked with Opera 11, Google Chrome 7.0.517.44 and FireFox 3.6.12 have seen no difference with your site design.
Did you declare the DTD (DOCTYPE)?
Read this:
http://msdn.microsoft.com/en-us/library/bb250395.aspx
It looks that browsers have different ways to display the borders, but the DOCTYPE declaration (which goes at the top of the html document) force them to comply with the actual standards, at least in regard of css box model.
Note: I always use the xhtml transitional DTD to make my document as much compatible as possible...
Good luck!
Try:
table{border-collapse:collapse;}
Its good practice to always set table{border-collapse:collapse;} in the css, and then use cell-padding="0" and cell-spacing="0" in the html anyway.