I know that Alt is used for images in HTML, but is there a way to apply it to text via CSS?
Example:
input { color: #62161e; font-size: 25px; font-family: Lintel; }
So say Lintel does not display properly in some browsers. Is there an alt option to display Helvetica or something?
In CSS, you can specify a list of font families to follow and the browser will use the first one that it supports. So if you want to display Helvetica if Lintel is unavailable, you would simply do this:
font-family: Lintel, Helvetica;
Remember that if the font family has a space in it, you need to surround it in double quotes, like with the line I use for my website:
font-family: "Segoe UI", Arial, Helvetica, sans-serif;
You can provide multiple fonts and the browser will pick the first available font.
Yes, you can chain fonts.
font-family: Lintel, Helvetica, Arial, sans-serif;
If you are defining both font-size and font-family I suggest you use the shorthand version:
font: 25px Lintel, Helvetica, Arial, sans-serif;
You can add more to this as well:
font: (weight) (size)/(line-height) (family);
The only two that are required are size and family.
font: bold 30px/25px Lintel, Helvetica, Arial, sans-serif;
Related
It's screenshot of the code I am working with. I want to understand the font-family declaration syntax and in what sequence it works
Here's the code:
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Helvetica Neue", Arial, sans-serif;
font-size: 1.6rem;
line-height: 1.5;
text-align: center;
color: #333333;
margin: 0;
}
Basically I want to understand the font-family declaration syntax
The font-family property can hold several fonts. If the browser does not support the first font, it tries the next font. If the browser supports "Segoe UI" it will be "Segoe UI" otherwise it moves to next.
So as a best practice order your fonts in the order you need.
The font family is applied in order from the font you entered first.
For example, if a user's PC does not have a font, it is applied in order from the very beginning.
if there is a corresponding font, the fonts that follow the applied font will not be applied.
If the font name contains spaces, use quotation marks to indicate that it is a single font.
I'm not good at English, so I don't know if I delivered it correctly, but I hope it helped.
What's the difference of space and comma in CSS property value(not for selector)?
font:bold 60px helvetical, arial, sans-serif;
I just had a test, it has different effect when change comma to space or vice versa in above style, so I want to know when to use space/comma?
Space:
Each value make different function. For example:
font: bold 60px helvetica, arial, sans-serif;
bold = font-weight: bold;
60px = font-size: 60px;
bold do the weight and 60px do the size, these two are different from each other.
Comma:
helvetica, arial, sans-serif = font-family: helvetica, arial, sans-serif;
Values in comma do the same function. They all change font-family.
In this case:
If helvetica it's not supported then loads arial, if arial it's not supported then loads sans-serif.
Using fonts with two words:
If you use fonts that contains two words and have spaces like Roboto Slab.
For these fonts you have to put them on double quotes "roboto slab".
Example: font: bold 60px "roboto slab", arial, sans-serif;
the following font style code does not work in firefox, I tested it in chrome and iexplorer and it works, so must be a compatibility problem.
font: italic normal normal normal 12px/15.3599996566772px Helvetica, Arial, 'lucida grande', tahoma, verdana, arial, sans-serif;
Can someone confirm it, or maybe there's an alternative for firefox.
FIX:
font: italic normal normal 12px/15.3599996566772px Helvetica, Arial, 'lucida grande', tahoma, verdana, arial, sans-serif;
For FireFox, you should set all the properties without using the shorthand property. font: is the shorthand property for many other font properties:
Instead it should look like this:
font-family: monospace;
font-size: 20px;
font-weight: bold;
color: blue;
http://www.w3schools.com/css/css_font.asp
http://www.w3schools.com/cssref/pr_font_font.asp
This appears to be a bug in Firefox. In the Developer Tools, no errors are shown, but when inspecting style sheets, the styles for the element are empty.
A quick workaround is to remove of the normal keywords (or all of them, since they are redundant: all sub-properties not set explicitly in a font shorthand are set to their initial values).
P.S. Your code is correct, Firefox just does not handle it well. As a reference to font shorthand syntax (if you use it), use the W3C CSS 2.1 specification.
For google fonts the font-family and font-weight are variables. The short syntax should be
font: 400 "Open Sans", Helvetica, Arial, sans-serif;
But I get invalid property value,
Is there a way to declare just font-weight and font family in the short version? I want everything else to stay as it is (font style etc)
I believe the font-size must be specified when using font shorthand.font: 400 12px "Open Sans, Helvetica, Arial, sans-serif;
See http://www.impressivewebs.com/css-font-shorthand-property-cheat-sheet/ and http://www.w3.org/wiki/CSS/Properties/font
You'll need to use the good old font-weight and font-family instead of the shorthand.
I have my fonts set in my style.css:
font-family: "Arial, Verdana, sans-serif";
But my website still seems to use sans serif. What is the problem here?
The commas in your CSS font-family specification need to be outside the quotes.
For example:
font-family: "Arial", "Verdana", sans-serif; /* And you should really
omit the quotes if it's only one word */
Not
font-family: "Arial, Verdana, sans-serif";
Otherwise, the CSS parser thinks you're looking for a font called "Arial, Verdana, sans-serif", which clearly doesn't exist.
Try removing your "" from the font-family definition:
font-family: tahoma, sans-serif;
Like that. Only put the " around when you have multiple words such as
font-family: "mutiple word font name",tahoma, sans-serif;