Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow:hidden messing with margins in Chrome and Safari

Tags:

css

margin

I have set up some divs for my layout, a main div and a menu div.

They look perfect in Firefox, but for some reason, Chrome and Safari get messed up.

For some reason the width of the div gets smaller when overflow:hidden; is added to the CSS. I need overflow:hidden; though, because I have other floats inside the main div. You can see the example here:

http://jsfiddle.net/kR7rs/2/

It shows up fine in Firefox, but in Safari and Chrome, there's a margin on the right side of the div as well.

like image 260
Rob Avatar asked Aug 08 '11 20:08

Rob


People also ask

What is overflow-clip-margin?

The CSS overflow-clip-margin property determines how far the overflow of an element can go beyond the element's box before being clipped. This area is called the overflow clip edge.

Why is my page overflowing?

An overflow issue occurs when a horizontal scrollbar unintentionally appears on a web page, allowing the user to scroll horizontally. It can be caused by different factors. It could occur because of unexpectedly wide content or a fixed-width element that is wider than the viewport.

Why is overflow hidden?

overflow : hidden is a property which will make any text going out of your div as hidden i.e. it will not be shown on screen and will be clipped. overflow : auto will make scroll bar's appear if the text goes out of your div.


1 Answers

Removing the margin from main seems to fix it:

http://jsfiddle.net/kR7rs/3/

What I think it happening is that when overflow:hidden is set, the entire element wraps around the floats instead of the text within the div. So this gives the result in the fiddle. Then if you set a margin on it also, the width is decreased further by the left padding.

Kind of seems like a bug.

(Don't have FF right now to test it and see if it breaks it for FF.)

like image 188
James Montagne Avatar answered Sep 18 '22 08:09

James Montagne