i noticed an issue when using Less with font shorthand
.font(#weight: 300, #size: 22px, #height: 32px) {
font: #weight #size/#height "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif;
}
the above fails with
this.a.toCSS is not a function
http://localhost/tumblr/modern1/css/style.less on line 1, column 0:
1. #highlight: #cb1e16;
2. #shade1: #cb1e16;
when i split the properties up it works
.font(#weight: 300, #size: 22px, #height: 32px) {
font-weight: #weight;
font-size: #size;
line-height: #height;
font-family: "Yanone Kaffeesatz", "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif;
}
i think its because of the slash / thats causing the problem, i think since Less can do calculations, eg. 2px + 5 = 7px its trying to do a divide?
Just ran into this issue, the escape function (for less.js anyway) is:
e()
Like this
font: #weight #size e('/') #height "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif;
The forward slash / character is causing the LESS compiler to divide your font-size by your line-height. You can:
Separate your CSS into non-shorthand, separate rules
font-size: #size;
line-height: #height;
Escape some or all of your LESS font shorthand rule. The slash / itself is the best part to escape. You can use the e, e("/") escape syntax, or the newer, better documented tilde-quote ~"/". You can also use the LESS string interpolation #{} syntax to insert your variables.
Try this:
font: #weight #size~"/"#height "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif;
Or this:
font: #weight ~"#{size}/#{height}" "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif;
LESS 1.4 and above now have a "strictMath" option that solves the ambiguity between and font shorthand. In 1.4 it is disabled by default to make transitioning easier, but in later versions it will be enabled by default.
See the 1.4 notes here
When strictMath is enabled, all math operations must be wrapped in parenthesis (10px / 5px) and the forward slash in the font short will not be interpreted as division.
Related
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;
How to write a CSS font style for the following font:
font-family: Comic Sans MS CSS rule doesn't work.
The font may exist with different names, and not at all on some systems, so you need to use different variations and fallback to get the closest possible look on all systems:
font-family: "Comic Sans MS", "Comic Sans", cursive;
Be careful what you use this font for, though. Many consider it as ugly and overused, so it should not be use for something that should look professional.
The httpd dæmon on OpenBSD uses the following stylesheet for all of its error messages, which presumably covers all the Comic Sans variations on non-Windows systems:
http://openbsd.su/src/usr.sbin/httpd/server_http.c#server_abort_http
810 style = "body { background-color: white; color: black; font-family: "
811 "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n"
812 "hr { border: 0; border-bottom: 1px dashed; }\n";
E.g., try this:
font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif;
You need to use quote marks.
font-family: "Comic Sans MS", cursive, sans-serif;
Although you really really shouldn't use comic sans. The font has massive stigma attached to it's use; it's not seen as professional at all.
Use quotes to surround the font:
font-family: "Comic Sans MS";
That should solve the problem.
How can I apply !important to the following syle:
font-family: "Trebuchet MS" , Verdana, Helvetica, Sans-Serif;
I've tried this, but doesn't work:
font-family: "Trebuchet MS" , Verdana, Helvetica, Sans-Serif !important;
Select the children within the parent container with a wildcard (*):
div * {font-family: "Trebuchet MS" , Verdana, Helvetica, Sans-Serif !important; }
http://jsfiddle.net/4d3K4/50/
The code is fine. It would vary depending on which elements you are giving the property to. It's better if you use specific selectors such as classes:
http://jsfiddle.net/4d3K4/
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;
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;