CSS font size different in chrome and firefox [duplicate] - css

I built a site and the problem is, chrome display font-size 1px bigger than Firefox. I tried several ways to match the font-size, specified it in px, in % set the body to 100% and then the elements to 0.875em. None of those work. It stills display 1 pixel greater in chrome.
This is the code I'm using for font-sizes:
body {
font-size: 100%;
}
* {
margin:0;
padding:0;
text-decoration: none;
font-family:helvetica, arial, sans-serif;
}
#geral {
width:1000px;
margin:0 auto;
position:relative;
font-size:0.875em;
}
Where the #geral wraps the entire site and there is no other font-size statement on the CSS, the source can be viewed in the link I posted.
I wonder if there is a way to fix that or if I'll have to specify different font-sizes for each browser?

I suggest you use a CSS reset like the one from YUI. It will make your pages much more consistent across all browsers, including font rendering. It makes the biggest difference with IE and the other browsers, but it gets rid of all manner of inconsistencies.

Fwiw at this date, I myself have just recently learned that good CSS-coding practice is to define absolute font-size only for the HTML or BODY element, and to define all other font-sizes relatively, that is, in terms of this size (i.e., using em or %).
If you do that, you only need single out webkit browsers (Chrome, Safari) from the others (Gecko, IE, etc.). So, for example, you might have defined in your stylesheet,
body {
font-size: 16px;
}
Then at the bottom of the stylesheet, you can include this
#media screen and (-webkit-min-device-pixel-ratio:0) {
Body {
font-size: 20px;
}
}
(See also Chrome conditional comments)
This works for me. But one side-effect is to also rescale any non-text elements that are sized relatively, and this may or may not be desirable.

<script>
if(navigator.userAgent.indexOf("Chrome") != -1 )
{
var fontsize = "<style>body{font-size: 125%;}</style>";
}
else if(navigator.userAgent.indexOf("Opera") != -1 )
{
var fontsize = "<style>body{font-size: 100%;}</style>";
}
else if(navigator.userAgent.indexOf("Firefox") != -1 )
{
var fontsize = "<style>body{font-size: 100%;}</style>";
}
else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
{
var fontsize = "<style>body {font-size: 100%;}</style>";
}
else
{
var fontsize = "<style>body {font-size: 100%;}</style>";
}
</script>
<script>document.writeln(fontsize);</script>

Works fine here:
Chrome 9.0:
Firefox 4.0 beta 10:

em is scalable and px is not. Set the font to a defined px size and you should be ok. em can be desirable in certain circumstances, but if you are worried about 1px then you should set strict pixel sizes.
EDIT: Just reread and I see you have tried setting the height as pixels already. Don't have a clue then as I don't have Chrome installed here to test. :(

if you have web page to print then
add css
<link rel="stylesheet" type="text/css" href="report.css" media="print" />
in css file
body {
padding: 3px;
margin: 0.5px;
background-position: center;
color: #000000;
background: #ffffff;
font-family: Arial;
font-size: 13pt;
}
this works for me

I too have had this problem and I've decided, where possible to go with font-size: small (or x-small etc). This gives you a basic range of scalable font sizes without having to look for fiddily css or messing around with JS. It works with IE, FF and Chrome.

I'm getting a good enough similarity in rendering between Firefox and Chrome when I use this css (it works because Firefox does not yet implement 'zoom'):
body {zoom: .7}
But it still isn't pixel perfect.
Note that I use 'rem' units instead of 'px' units everywhere, as this works better when I use more than one font on a page.
Note that I've set Windows display resolution to 150% to compensate for my poor vision. When I set it back to 100%, the problem of different sizes remains. So this isn't the issue.
I'm sure there is no standard that says that pages must look the same on different browsers, but using 'zoom' seems to help in this regard.
Unless this scale factor problem is due to a misconfiguration on my computer.

Related

removing margin which browser getting automatically

When we are creating a web page using bootstrap we can set margins. But web browser also gets some margins. Although code as div(class="container-fluid") or code as margin:0; and padding:0; based on the container in the CSS file, I couldn't solve the problem. Can you help me?
Some browsers have a margin on the body tag. Set that to 0 somewhere in your css.
body {
margin: 0;
}
This is Browser default margin for body:
Fix It Like this:
body {
margin:0;
}
Set the margin to zero on any element is simple just type something like
body{
margin:0
}
Although sometimes bootstrap has his own margin rules included like setting margin on h tags, you could remove them as well by using more specific rules (read about specificity here) or by using important
h4{
margin: 0 !important
}
The reason for that is browsers have default styling for elements.
To reset margin only on body element you can use:
body {
margin: 0;
}
To reset all styling (which is not so-bad thing) in all browsers you can use css library called normalize.css.
Normalize.css makes browsers render all elements more consistently and in line with modern standards. It precisely targets only the styles that need normalizing.
This library is used by big companies as GitHub, Twitter, Soundcloud, Guardian, Medium and many others.
Although you put container-fluid, sometimes it doesn't make the width 100% fit the screen because browsers make a default margin and padding.To make it fit the screen you have to do like this.
body{
padding: 0;
margin: 0;
}
If it doesn't work make them important as following.
body{
padding: 0 !important;
margin: 0 !important;
}

How can I stop IE from compounding relative font sizes in pseudo-elements?

I have some icons that are set via pseudoelement in CSS, like this:
.button a:before {
font-size: 1.3em;
font-family: font-awesome;
content: "*";
}
And there are other, similar declarations elsewhere, like
.button .otherclass a:before {
font-size: 1.35em;
}
This works fine with modern web browsers, but IE >= 9 compounds all the font sizes, so that the resulting icon is enormous (like 5 times its size). How can I prevent this from happening?
(BTW, the actual code with the problem is here.)
This is a bug in IE, as reported on the Microsoft Connect page mentioned by #Aibrean, but the page also shows that Microsoft does not admit that this is a bug (they say they cannot reproduce it). It can be reproduced in IE 11 on Win 7 with the following simple document:
<style>
.foo, .bar:before {
font-size: 2em;
content: "X";
}
.bar:before {
font-size: 5em;
}
</style>
X<span class=foo>X</span>
<span class=bar>bar</span>
The second X should be 5 times as big as normal X, but it is actually 10 times as big in IE, since IE incorrectly multiplies the effects of 2em and 5em.
The workaround, it seems, is to organize your style sheet so that the font size of generated content is set once only for each element. That is, so that there are no two font-size declarations that apply to the same :before or :after pseudo-element.
There is a slightly better solution than using absolute font-sizes, and that is to use rem inside the :before or :after declaration.
em and rem units are based of the default font-size (commonly 16px, so 1rem = 1em = 16px) so if the user changes their default font then your font will change too. However rem units do not compound.
rem support is growing but you can use both (if you don't need compounding):
font-size: 2em
font-size: 2rem
and then those browsers (e.g. IE8) that don't support rem will use em. And as IE8 doesn't have the compounding issue to which you refer, this actually works nicely.

CSS issue, targeting font-size in IE8

Please take a look at my site: http://burnett.inigowebdesign.co.uk/local_area
I am using Twitter bootstrap CSS (with HTML5 Boilerplate), Modernizr, and Google fonts using #font-face.
I am using modernizr to test for a browser's support of fontface- it not supported, I need to change the font-size (otherwise it will be far too large)
I am testing the site for compatibility and have noticed in IE8 (and early versions of Safari & Opera) my rules for font-size are being ignored. In particular, the h3 elements in the main list (that you can see on the left in the green box) don't seem to respond to any CSS I apply to them. I am using Firebug to inspect the rules, and can't find any possible conflicts. It even ignores !important. In fact, the only way I can style them at all is to use inline CSS.
What is going on??
The text is differ due to different font-size define in each css file.
In normalize.css h3 have 1.17em font size and in fontface.css font size define 50px . It might be possible the browser rendering the file in some different orders.
normalize.css file using this property.
h3 {
font-size: 1.17em;
margin: 1em 0;
}
fontface.css file using this property.
h3 {
font-size: 50px;
/* letter-spacing: normal;
font-weight: normal;*/
line-height: 36px;
}

Effect of !important declaration when sizing (fonts) with rem

UPDATE: Please note that I am seeing this issue only in Chrome (latest version). Everything seems to be fine in Firefox.
By definition:
The rem unit is relative to the root—or the <html>—element. That means
that we can define a single font size on the <html> element and define
all rem units to be a percentage of that.
Let me explain my situation with an example...
Relevant CSS:
html {
font-size: 87.5%;
}
body {
font-size: 17px;
font-size: 1.21428571rem;
}
code {
font-size: 14px !important;
font-size: 1rem !important;
}
I am using the !important declaration to override the font-size of inline code.
The thing is, I noticed that the font-size of code blocks is much smaller than 14px, most probably 12px. But if I remove the !important declaration and set the font-size on a specific code element (styling a specific inline code element), the fonts-size is nice and fine at what appears to be 14px.
Does you have any idea as to how !important declarations may affect sizing in rem's? (Especially considering in my case.)
First off !important is lazy coding and dangerous to maintainability. It's toxic and breaks the nature of CSS (the Cascading portion). Avoid it at all costs.
Second:
code {
font-size: 14px !important;
font-size: 1rem !important;
}
Might as well be written:
code {
font-size: 1rem !important;
}
The second rule overrides the first (again, the Cascading nature of CSS)
rem stands for root em, which is the font-size of the top level element (i.e., html)
and what your rule is saying 1 x the em of the html element, with is 87.5% of the browser default.
EDIT:
Your <p> tags have a font-size of 100% inherited from the parent element which is eventually inherited from body and body has a 1.2142857rem which is roughly 17px This is why you're seeing a difference in font sizes, which is also exacerbated by the the difference of monospace and sans serif fonts.
Okay, the issue was with (1) font-family not defined for code and pre blocks, which meant Chrome and other webkit browsers chose some monospace font that appears smaller (2) line-height was smaller (almost equal to the font-size).
Fixing these two has solved the problem.
I have no idea why Chrome Dev Tools Web Inspector's "Computed Style" shows 11px as the font-size (also applies to any webkit browser, including Safari). I can confirm that it's showing the wrong value because by changing the font to Arial I could easily tell that it's 14px.
Also, after setting the font-family on code and pre blocks, Chrome now shows the correct computed font-size value.

Why do I get a horizontal scrollbar for width: 100% in chrome?

Starting with:
html, body
{
padding: 0;
width: 100%;
font: 100%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
}
Chrome decides that the width should be 1600px, which is wider than my current display, let alone the current Chrome window. I'm sure this is an old chestnut, but I'm failing to find the right tree.
I posted a complete example to git://github.com/bimargulies/css-mystery.git.
One note: My macbook was plugged into a very wide monitor, and is now not. The 1600px seems to me to be related to that, but I don't know how to make it go away except to reboot.
In the chrome devo tools, looking at the effective styles for the , I see:
width: 1600px;
html, body - 100%
That 1600 is very mysterious. And this is after a reboot.
EDIT bingo: buried in the style sheet main.css, from someone else I work 'with', was 'minWidth: 100em;' on body. oops.
You need to add margin: 0 to remove the default margin on the body element.
Are you sure you need width: 100%?
html and body are by default "full width" due to being block-level elements.
Try using a CSS reset...
http://meyerweb.com/eric/tools/css/reset/index.html
... to set all CSS properties to their default values.
I hope this helps.
Hristo
For the record, I think it's best to actually have the explanation in an answer.
There was another CSS clause way down the file:
body
{
minWidth: 100em;
}
I didn't spot it, and the Chrome 'Computed Styles' box does not include this in the 'explanation' of the 1600px in the same way that it include width styles.
I had same issue. could be other div in body is having padding or margin.
margin or padding can cause it.
in my case, was padding

Resources