Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 464
Michiel Avatar asked Mar 27 '10 23:03

Michiel


People also ask

Does border Add to width CSS?

By default in the CSS box model, the width and height you assign to an element is applied only to the element's content box. If the element has any border or padding, this is then added to the width and height to arrive at the size of the box that's rendered on the screen.

Is CSS compatible with all browsers?

Given the extent of device-browser fragmentation in the world, CSS will naturally have to be compatible with multiple browsers to allow a site to render perfectly for users with different browser preferences. CSS is a styling aspect used across websites to make them look stylistically superior.

What is webkit border?

The -webkit-border-before CSS property is a shorthand property for setting the individual logical block start border property values in a single place in the style sheet.


1 Answers

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

like image 156
Clarence Liu Avatar answered Oct 26 '22 04:10

Clarence Liu