Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox: wrong interpretation of box model?

Tags:

css

firefox

I just discovered strange behaviour of Firefox.

If I have a table cell of 100px height, and add 20px padding to it - it's total height should become 140px.

All browsers act correctly, Firefox 8.0 ignores the padding:

http://jsfiddle.net/8wDde/

Anyone knowing a fix?

like image 884
ptriek Avatar asked Dec 03 '11 18:12

ptriek


People also ask

What is the box model in HTML?

In a web page, every element is rendered as a rectangular box. The box model describes how the element’s content, padding, border, and margin determine the space occupied by the element and its relation to other elements in the page. Depending on the element’s display property, its box may be one of two types: a block box or an inline box.

Why is the box model bad for web design?

The result is that tightly spaced elements are constantly prone to overlapping onto each other and breaking entire layout flows. Probably the simplest argument against the default box model is that it approaches layout differently than actual designers do.

How do I know if my box model is correct?

Your browser developer tools can make understanding the box model far easier. If you inspect an element in Firefox's DevTools, you can see the size of the element plus its margin, padding, and border. Inspecting an element in this way is a great way to find out if your box is really the size you think it is!

How does the box model work?

The box model allows us to add a border around elements, and to define space between elements. In order to set the width and height of an element correctly in all browsers, you need to know how the box model works. Important: When you set the width and height properties of an element with CSS, you just set the width and height of the content area.


2 Answers

It seems the best cross browser solution may be to set the full height of the table row equal to height and padding of the cell:

tr {height: 140px;}

See: http://jsfiddle.net/8wDde/19/

like image 88
ScottS Avatar answered Oct 07 '22 02:10

ScottS


that is a strange behave. add display:block; can fix the problem. tested in FF8.01 see:

http://jsfiddle.net/8wDde/1/

But I also do not know why?

I searched in https://developer.mozilla.org/en-US/search?q=table+padding, but did not find anything. May be you can also try to search in there.

UPDATE: http://jsfiddle.net/8wDde/7/

add overflow:hidden to avoid the td change line.

like image 23
Giberno Avatar answered Oct 07 '22 02:10

Giberno