Why does font css property remove bold weight? - html

I was tasked with removing unnecessary tags from computer-generated HTML that had a lot of useless tags (I only wanted to keep color/strong/em information). I came along something similar to this HTML:
<b>
<span style="FONT: 20pt "Arial"">
<strong>bold</strong> not bold <b>bold</b> not bold
</span>
</b>
For me (on chrome & firefox), it shows the bold text as bold and the not bold text as not bold, and I am confused as to why this is. In particular, this makes my task more complicated: I thought I could just remove the tags that do not have color/strong/em info, so change it to something like this:
<b>
<strong>bold</strong> not bold <strong>bold</strong> not bold
</b>
But now, all is bold instead of what it used to be.
I tried to find out what I could put in the FONT style to reproduce this behaviour:
Replacing Arial with foo kept the behaviour:
<b>
<span style="FONT: 20pt foo">
<strong>bold</strong> not bold <b>bold</b> not bold <!-- not bold is actually not bold! 20pt is applied -->
</span>
</b>
Switching the size and font changed the behaviour:
<b>
<span style="FONT: "Arial" 20pt">
<strong>bold</strong> not bold <b>bold</b> not bold <!-- everything is bold. 20pt is _not_ applied -->
</span>
</b>
Any of the two values on their own did nothing much:
<b>
<span style="FONT: "Arial"">
<strong>bold</strong> not bold <b>bold</b> not bold <!-- everything is bold -->
</span>
</b>
<b>
<span style="FONT: 20pt">
<strong>bold</strong> not bold <b>bold</b> not bold <!-- everything is bold -->
</span>
</b>
<b>
<span style="FONT: 20pt "Arial"">
<strong>bold</strong> not bold <b>bold</b> not bold
</span>
</b>
<div>Replacing `Arial` with `foo` kept the behaviour:</div>
<b>
<span style="FONT: 20pt foo">
<strong>bold</strong> not bold <b>bold</b> not bold
<!-- not bold is actually not bold! 20pt is applied -->
</span>
</b>
<div>Switching the size and font changed the behaviour:</div>
<b>
<span style="FONT: "Arial" 20pt">
<strong>bold</strong> not bold <b>bold</b> not bold
<!-- everything is bold. 20pt is _not_ applied -->
</span>
</b>
<div>Any of the two values on their own did nothing much:</div>
<b>
<span style="FONT: "Arial"">
<strong>bold</strong> not bold <b>bold</b> not bold
<!-- everything is bold -->
</span>
</b>
<b>
<span style="FONT: 20pt">
<strong>bold</strong> not bold <b>bold</b> not bold
<!-- everything is bold -->
</span>
</b>
Can anyone explain this behaviour, or at least tell me what styles I should look for that cancel outer styles?

I think I found the answer to my question, on the font css property documentation page. It states:
As with any shorthand property, any individual value that is not
specified is set to its corresponding initial value (possibly
overriding values previously set using non-shorthand properties).
Though not directly settable by font, the longhands font-size-adjust
and font-kerning are also reset to their initial values.
(My emphasis)
And a bit further down:
Initial value as each of the properties of the shorthand:
font-style: normal
font-variant: normal
font-weight: normal
font-stretch: normal
font-size: medium
line-height: normal
font-family: depends on user agent
So setting font: 20pt arial is equivalent to setting font-style: normal;font-variant: normal;font-weight: normal;font-stretch: normal;font-size: 20pt;line-height: normal;font-family: arial
In particular, the font-weight is reset from bold (or whatever it was) to normal.
So to solve my underlying question, I should look for font tags that do not specify the weight.
P.S. The reason that font: arial 20pt did not have this behaviour is because this is not an allowed value for font, so it is ignored:
If font is specified as a shorthand for several font-related properties, then:
it must include values for: <font-size> <font-family>
font-style, font-variant and font-weight must precede font-size
font-family must be the last value specified.
And in font: arial 20pt the font-family is not the last value specified.

Fonts depend on your actual browser and actual font. ref: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
Fonts have a particular weight which corresponds to one of the numbers
in Common weight name mapping. However some fonts, called variable
fonts, can support a range of weights with a more or less fine
granularity, and this can give the designer a much closer degree of
control over the chosen weight.
WHICH of the copyrighted or not fonts do you have? Depends. Browser, computer, CSS etc. but we cannot tell here.
Always specify a fallback (sans-serif in this case) This can all get a bit "tricky".
Bottom line: put all this in CSS and use classes so you can actually control it best and less HTML overall when you decide to change things Like pt is not normally great for visual but is for printed but not used much in modern HTML as a size. Now if you decide to change the size you have a lot of places to change it but if in CSS only one.
Now for some examples: (not all inclusive of the topic by any means)
.container {
font-weight: normal;
margin: 1em;
}
.container .fonty {
font-size: 20pt;
font-family: Arial, Helvetica, Verdana, "Gill Sans", sans-serif;
}
.heavy-one {
font-weight: 600;
}
.heavy-two {
font-weight: 900;
}
<div class="container">
<span class="fonty">
<span class="heavy-one">bold</span> not bold <span class="heavy-two">bolder</span> not bold
</span>
</div>
<div class="container">
<span class="fonty heavy-container">
<span class="heavy-one">bold</span> not bold <span class="heavy-two">bolder</span> not bold
</span>
</div>
<p>One with style in tags: (don't do this)
<span>
<span style="font-weight: normal; font-size: 20pt; font-family: 'arial', 'Arial', sans-serif;">
<span style="font-weight: bold;">bold</span> not bold <span style="font-weight: bold;">bold</span> not bold</span>
</span>
</p>
<p>Second with style in tags: (don't do this, bolder not great IMHO as it is one step heavier)</p>
<span style="font-weight: normal; font-size: 20pt; font-family: 'arial', 'Arial', sans-serif;">
<span style="font-weight: bold;">bold</span> not bold <span style="font-weight: bolder;">bold</span> not bold</span>
<p>Third with style in tags and <strong>: (don't do this) This also shows multiple similar font families and the fallback to "sans-serif" you should always include</p>
<span style="font-weight: normal; font-size: 20pt; font-family: Arial, Helvetica, Verdana, sans-serif;"><strong>bold</strong> not bold <strong>bold</strong> not bold</span>

Related

font-weight property is not working in inline style

I am inserting html code through database, we don't have separate styling sheet. So we are using inline styling.
I used below code
<li style="font-family: Arial; font-size: 13pt;Color: #711984; font-weight: bold">
Cross-border Transfer
</li>
But font-weight property is not applicable, I don't see bold fonts.
I tried below code, it works but I don't think its recommended for best practices:
<b>
<li style="font-family: Arial; font-size: 13pt;Color: #711984;">
Cross-border Transfer
</li>
</b>
Pl

Font size not changing in HTML

So, after I tried all the answers in the forums over here, the font size of my webpage won't change. Here's what I currently have:
<font size="40px" face="Didot">Hello</font>
Okay, it will set to 40px, but if I try to make another one using 20px it won't change the font size:
<font size="20px" face="Didot">World</font>
Whole code for those who want to check for themselves
<html>
<font size="40px" face="Didot">Hello</font>
<font size="20px" face="Didot">World</font>
</html>
<font> tag is deprecated. ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font )
Use CSS styling instead. See the example below.
.size40 {
font: 40px/1.5 Didot, serif;
}
.size20 {
font: 20px/1.5 Didot, serif;
}
<span class="size40">Hello</span>
<span class="size20">World</span>
If you are looking for ways to do inline styling you can follow this approach
<html>
<div style="font-size:40px; font-family:Didot">Hello</div>
<div style="font-size:20px; font-family:Didot">World</div>
</html>
But I would recommend to create a separate css file and define styles there. And import those styles in your html using script tags
As said in the previous answer the source is deprecated but if you insists on wanting to try you can use the following:
<font face="Verdana, Geneva, sans-serif" size="+7">Hello</font>
<font face="Verdana, Geneva, sans-serif" size="+4">World</font>
If it still doesn't work, use CSS:
<p>Hello</p>
<p>World</p>
⠀
p:nth-child(1){
font-family: Didot;
font-size: 40px;
}
p:nth-child(2){
font-family: Didot;
font-size: 20px;
}

How to set bold font instead font weight in Bootstrap 4 SCSS?

I'm trying to build Bootstrap from SCSS, but I'm not experienced in front-end technologies at all. Is there any way to set a bold-by-default font instead font-weight everywhere it's used? The font-weight version is rendered distorted. I'm using a custom CSS now overriding the font-family everywhere where it's needed (h1...h6, b, strong, etc.) but it's not too convenient.
use font-weight-bold class to get bold font.
Load a bold font by default:
*{
font-family: 'Lato', sans-serif;
font-weight: 900;
}
<link href="https://fonts.googleapis.com/css?family=Lato:900" rel="stylesheet">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>etc.</p>
<span>everything is bold now</span>

Is that possible to use several weight of a web font in a email html ? (or 2 different fonts ?)

I'm building a email on html with the inline css. I need to build it with the google font Open Sans and using the light one with font-weight:300 for the text and the bold one with font-weight: 700 for titles.
I customed on googlefont website the url to have both particularities I needed like that :
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,700" rel="stylesheet">
The fact is that my email seems to apply by default the property 700 to all the page and can't find the 300 one if I put in my inline css the font-weight to 300.
However the 300 weight seems to be applied in a text, but I don't know why or understand the logic that could help me to apply a light weight whenever I want.
Does anyone know how if I can use Open Sans bold and light in the same page in a email html?
here is the codepen :
https://codepen.io/Katchou/pen/zzzLOy
You can use a different font-weight for the title and content
Refer the snippet
h3{
font-family:'Open-sans', sans-serif;
font-weight: 700;
}
p{
font-family:'Open-sans', sans-serif;
font-weight: 300;
}
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<span>
<h3>Heading</h3>
<p>Content</p>
</span>
Or you can use
<span>
<h3 style="font-family:'Open-sans', sans-serif;font-weight:700">Heading</h3>
<p style="font-family:'Open-sans', sans-serif;font-weight:300">Content</p>
</span>
How's this? I can refine my answer if you add more information to the question.
EDIT:
You added a CodePen.
I got your title to show as Open Sans Light.
Check it out!
https://codepen.io/rickydam/pen/QggBja
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style>
#font-face {
font-family: 'Open Sans Light';
src:url(https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTRa1RVmPjeKy21_GQJaLlJI.woff) format('woff');
}
</style>
<span>
<font face="Open Sans">
Hello world
</font>
<br>
<font face="Open Sans Light">
Hello world
</font>
<br>
<font face="Open Sans" style="font-weight:700">
Hello world
</font>
</span>

Inconsisent gap between number and text

I got strange spacing issues. There is number and each text parallel. And there is different spacing between 1, 4, 7 and 'each' text. How can we fix this issue or it can't be fixed. I have not used any spacing and extra css properties.
#import url('https://fonts.googleapis.com/css?family=Spectral');
#import url('https://fonts.googleapis.com/css?family=Open+Sans|Spectral');
.bigger {
font-size: 40px;
}
p {
font-family: 'Open Sans', sans-serif;
}
<p>
<span class="bigger">81</span>
<small>each</small>
</p> <br>
<p>
<span class="bigger">84</span>
<small>each</small>
</p> <br>
<p>
<span class="bigger">87</span>
<small>each</small>
</p> <br>
Although using a monospace font is a nice workaround, you could solve this with your original font if it has the correct OpenType features.
The difference in the space that a digit occupies is caused by the width of the digit (as opposed to kerning or letter spacing, as suggested in the other answers). The width is proportional — the 1 is narrower than the 4.
But a font can also offer tabular figures, where each digit is of equal width:
You can enable this in CSS with font-feature-settings: 'tnum';. Or to use other OpenType features and take care of browser inconsistencies, see Utility OpenType.
That is the issue of letter spacing of the font. You should use a monospace font to achieve same spacing for all characters.
Try the below snippet.
.bigger {
font-size: 40px;
}
p {
font-family: monospace;
}
<p>
<span class="bigger">81</span>
<small>each</small>
</p> <br>
<p>
<span class="bigger">84</span>
<small>each</small>
</p> <br>
<p>
<span class="bigger">87</span>
<small>each</small>
</p> <br>
The character 1 (and 7 sometimes) would usually be spaced out in most fonts. If you want uniform spacing, you should consider using monospace fonts.
Another improvement that you can make to your code is removing the spaces between tags.
Please check the code below:
#import url('https://fonts.googleapis.com/css?family=Spectral');
#import url('https://fonts.googleapis.com/css?family=Open+Sans|Spectral');
.bigger {
font-size: 40px;
}
p {
font-family: 'Open Sans', sans-serif;
}
<p>
<span class="bigger">81</span><small>each</small>
</p> <br>
<p>
<span class="bigger">84</span><small>each</small>
</p> <br>
<p>
<span class="bigger">87</span><small>each</small>
</p> <br>