I have a span and an input element that share the same CSS definition for font. Why does Chrome use different fonts for them? How would I fix this issue?
My objective is to make them look exactly the same in IE9, Chrome and FF.
CSS definitions (FIXED), if they still matter.
* {
font-family: Verdana,Helvetica,Arial,sans-serif; /* Moving here fixed it */
}
body {
/*font-family: Verdana,Helvetica,Arial,sans-serif; -- This caused the issue*/
font-size: .8em;
margin: 0;
padding: 0;
color: #000;
}
.button
{
text-align:center;
min-width:80px;
display:inline-block;
white-space:nowrap;
background-color:#4A8CF6;
color:#FFF;
padding:4px;
margin:1px;
border:0;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
font-size: .8em;
}
Solution
The problem was that the span elements inherited from my CSS definition for body and the input elements didn't. I had defined the font in my CSS with body { font-family:...; } like my computed results show and I thought that using display: inline-block; would force both of them to inherit the font from body but it did not.
The solution was to switch to using * { font-family:...; } for the font definitions. The button and clickable classes simply defined sizes and colors and such.
You have to literally specify input elements if you want them to have the same font like so:
/* Or input[type=submit] depending on your needs */
span, input {
font-family: Arial, sans-serif; /* Your font here */
}
Otherwise the browser uses the default values as your question shows. You're looking under Computed Styles which shows that Chrome has decided the values for you as you haven't specified them.
You should apply CSS reset rules in the beginning of your style sheet. Its purpose is to make all elements have the same look in all browser.
Examples:
http://developer.yahoo.com/yui/reset/
http://meyerweb.com/eric/tools/css/reset/
Related question which can be useful too: https://stackoverflow.com/questions/116754/best-css-reset
Related
I'm developing a site on Ubuntu. When I look at it in Firefox, it's a lot smaller than when I view it in Chrome. Screenshots:
Both browsers have their default fonts set to DejaVu Serif at 16px. I haven't messed with Bootstrap's default font size. It's still 1rem.
What's accounting for this discrepancy, and is there a way to further normalize the differences between browsers?
EDIT: My scss, even though it's not relevant, because it was requested:
$theme-colors: (
"burnt-orange": #fa7334,
"light-blue": #67e2f5,
"dark-blue": #006f80,
"beige": #f5d5bc
);
.header-icon {
font-size: 1.4rem;
}
#jumbo {
background: transparent;
border: 1px solid grey;
}
#diva-sidebar ul {
list-style-type: none;
padding-left: 0.65em;
}
#footer a {
color: white;
}
.errors {
border: 1px solid #c70f36;
color: #c70f36;
background-color: #ffc0cb;
}
#import "~bootstrap/scss/bootstrap";
#import "~#fortawesome/fontawesome-pro/css/all.css";
.header-icon-link-blue {
color: theme-color("dark-blue") !important;
:hover {
color: theme-color-level("dark-blue", 2) !important;
}
}
.header-icon-link-orange {
color: theme-color("burnt-orange") !important;
:hover {
color: theme-color-level("burnt-orange", 2) !important;
}
}
.color-burnt-orange {
color: theme-color("burnt-orange");
}
EDIT: After adding
html {
font-size: 16px;
}
To my custom.scss file, but the problem persists.
I found a similar issue when designing sites using Bootstrap 4.x. The issue is Bootstrap uses the browser's default font size, and then sets relative font sizes from this. However, Firefox and Chrome seem to use a different default size, which causes issues most noticeably when you are using larger fonts on headings. The easiest solution is to set an exact base font size on the html to override the browser default, like so:
html {font-size:16px;}
I think, you need to prefix your css code. Because, all browsers has a prefix code so: -webkit, -o, -moz ets. Go this Link and past your css left column and copy css from right column: for example: Kindly mark it as Answer if it solved your problem :)
As you can see below, both Gecko and Blink performs an inconsistent height calculation for different inline-block elements, even though they all have the same css class. It seems like (*pause*) Trident is the only layout engine to get it right.
Did I forget to (re)set a property?
Furthermore, as you can see in this fiddle, if I change the padding from .3em to 1em Blink renders as expected. All elements gets the same height. Gecko is still "broken" though.
Does anyone know why this is happening and how to fix it?
<a> <button> <input> <span>
Gecko (Firefox v. 39.0)
Blink (Google Chrome v. 43.0.2357.132 m):
Trident (Internet Explorer v. 11.0.9600.17843):
body {
font: normal 15px arial;
padding: 1em;
}
.button {
background: #444444;
border: none;
box-sizing: content-box;
color: #ffffff;
cursor: pointer;
display: inline-block;
font-family: arial;
font-size: 1em;
height: auto;
line-height: normal;
margin: 0;
min-height: 1em;
padding: .3em;
text-decoration: none;
}
<a class="button" href="#">button</a><button class="button">button</button><input class="button" type="button" value="button" /><span class="button">button</span>
For Gecko (Firefox), it is due to borders on ::moz-focus-inner for form elements. If you notice, the form elements (input and button) are always ~2px wider and taller than other elements.
To solve it, always add this to your CSS (as part of your reset):
button::-moz-focus-inner{
border:0;
padding:0;
margin-top:-2px;
margin-bottom:-2px;
}
input::-moz-focus-inner{
border:0;
padding:0;
margin-top:-2px;
margin-bottom:-2px;
}
The negative margins are necessary so that the font displays "correctly" in the line-height. You may need to tweak the values to fit your line-height, but these values mostly work fine.
For Blink (Chrome), the elements are actually the same size, but the only issue is that they are "mis-aligned". You'll notice that sometimes the form elements display slightly lower than the others in an inline-block setting. To solve it, simply ensure that they all use the same vertical alignment, e.g.:
display: inline-block;
vertical-align: top;
It is always a good practice to declare the two properties above together - if you specify inline-block, always remember to specify the vertical alignment, in order to prevent misalignment.
I am trying to apply the following style changes to the reddit widget:
1) Change font to Oxygen Mono (the !important override in CSS is not working for font, although it is working for link color)
2) Trim the top of the widget to eliminate the blue bar completely
3) Prevent widget_arrows.gif from being displayed in the widget.
Any ideas?
FIDDLE
#import url(http://fonts.googleapis.com/css?family=Oxygen+Mono);
html {
font-family:'Oxygen Mono', Tahoma, Arial, sans-serif;
}
#reddit {
width:900px;
margin:auto;
font:'Oxygen Mono' !important;
}
#reddit a:link, #reddit a:visited, #reddit a:hover, #reddit a:active {
color:gray !important;
}
Sure you can override a font, you just need to specify the correct format - if you change only the font family, use font-family. A simple look in the debug tools also showed this as "Rule ignored due to invalid property value".
As for the rest, just pick them out with the element inspector and fix them:
/* Style the anchors specifically for CSS specificity */
#reddit a {
font-family:'Oxygen Mono' !important;
}
.reddit-header, .reddit-voting-arrows {
display:none !important;
}
Updated fiddle.
I have search input beside navigation toggler. I want to style the text of placeholder as navigation toggler's heading but they are not similar even if the properties are same.
See:
::-webkit-input-placeholder {
color:#B2B4B5;
font-weight:bold;
font-size:15px;
}
:-moz-placeholder {
color:#B2B4B5;
font-weight:bold;
font-size:15px;
}
::-moz-placeholder {
color:#B2B4B5;
font-weight:bold;
font-size:15px;
}
:-ms-input-placeholder {
color:#B2B4B5;
font-weight:bold;
font-size:15px;
}
#menu-toggler > h4 {
width:auto;
padding:0 0 0 40px;
height:25px;
color:#B2B4B5;
}
Why ? Is it a bug? I am using Mozilla FF.
not sure what's going on but these might help you:
IE: http://msdn.microsoft.com/en-us/library/ie/hh772745(v=vs.85).aspx
Firefox: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-placeholder?redirectlocale=en-US&redirectslug=CSS%2F%3A-moz-placeholder
CSS Tricks: http://css-tricks.com/snippets/css/style-placeholder-text/
There maybe other proprety on your CSS file that overrides the one you set, like if the text is labeled as and you have set properties for that
I've noticed that FF requires you to be very specific with styling placeholders.
Instead of
:-moz-placeholder
try
input:-moz-placeholder
as class names (for example). Same counts for the ::-moz-placeholder styling.
Be as specific as possible, since FF tends to overwrite the placeholder if it has a more specific styling on the element.
I am using a custom font (Oswald) for the headings or titles within my page. I believe that its' height is conflicting with the native fonts (Arial, san-serif etc.) and would like to know if there is a way to set both fonts evenly...? If more text is placed in later on, the gap difference becomes substantial.
Please take a look at what I have here: http://jsfiddle.net/x6v7F/
I have a temporary background fade in and out to illustrate.
thank you.
It doesn't seem to be a font-size issue, the issue seemed to be with you specifying the line-height
If you see this fiddle, you can see I've changed h1 and h2 to have these line-heights
h1 {
font: 16px 'Oswald', Arial, Helvetica, sans-serif;
text-transform: uppercase;
color:#000000;
margin:14px 0;
line-height: 100%; <----
}
h2 {
font: 12px 'Oswald', Arial, Helvetica, sans-serif;
text-transform: uppercase;
color:#BBBBBB;
margin-bottom: 14px;
line-height: 100%; <----
letter-spacing: .2px;
}
If you check that Fiddle, it seems to have fixed your problem?
Rob has 4 sections that sit side by side (you may have to bump up width of jsfiddle window). His prob is that he wants his sections to line up along the bottom, but is having issue because the varying text sizes between his body font and header fonts.
Many of the css grid frameworks try to address these type of issues: normalizing the heights of text and headers so that all lines fall on an imaginary grid of baselines.
To be honest, I would just give the sections a static height and leave some fuzzy space at the bottom for margin of error.
section { height: 370px; position:relative; }
section .button { position:absolute; bottom:0; right:0; }
Edit:
If you're looking for a dynamic section height, you'll have to leverage javascript magic. JQuery:
<style>
section { position:relative; padding-bottom:50px; }
section .button { position:absolute; bottom:0; right:0; }
<style>
<script>
var max_height = 0;
$('section').each(function() {
max_height = Math.max(max_height, $(this).height());
}).height(max_height);
</script>