Font messes up alignment of numbers - html

I'm using the Raleway font, but this font doesn't align numbers properly with letters.
You can see this in this snippet:
h1 {
font-family: Raleway;
font-size: 2rem;
border-bottom: 1px solid $text-color;
border-top: 1px solid $text-color;
padding: 2rem 0;
}
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<h1>5 Comments</h1>
Can I solve this easily? Or is this just a faulty font and should I chose another one?

You can simply change with the help of CSS
add font-feature-settings: 'lnum' 1; to your css file
so your new css will be:
h1 {
font-family: Raleway;
font-size: 2rem;
border-bottom: 1px solid $text-color;
border-top: 1px solid $text-color;
padding: 2rem 0;
font-feature-settings: 'lnum' 1;
}
Check out this too http://clagnut.com/sandbox/css3/

The Problem
This is part of the font itself and not something you can provide a quick fix for (unless you're dealing with very little text). If we look at Google Font's page for the Raleway font, we'll see that numbers have different alignment to letters:
If you don't want the numbers to be aligned like this, you're going to have to use a different font instead.
A Fix
You can fix this by wrapping the numbers you wish to change the alignment of in a separate element and adjusting their vertical-align separately, but this is probably going to be more effort than its worth. I've given an example of this below:
h1 {
font-family: Raleway;
font-size: 2rem;
border-bottom: 1px solid $text-color;
border-top: 1px solid $text-color;
padding: 2rem 0;
}
.raised {
display: inline-block;
vertical-align: 12%;
}
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<h1>
<span class="raised">5</span>
Comments
</h1>

2020 speaking
Depending on the font and the browser you can add
font-variant-numeric: lining-nums;
Source : https://css-tricks.com/almanac/properties/f/font-variant-numeric/

https://www.codesmite.com/article/fixing-raleway-and-similar-fonts-numerals
This article explains it all and gives de fully compatible css3 "solution".
This code do the magic:
.yourclass {
-webkit-font-feature-settings: "lnum";
-moz-font-feature-settings: "lnum";
font-feature-settings: "lnum";
}

It depends on "the number case setting" feature of your font supports.
still you can do it by following this
Further reading UX stackexchange

I created a version of Raleway with lining numerals as default to be used as The Definitive Solution for this problem. You can download the font files or just embed it into your HTML (using <link>) or CSS (using #import) with a single line of code, like you'd do with any other Google Font. Free, open source and available in all weights and styles:
https://h-ibaldo.github.io/Raleway_Fixed_Numerals/

I know you've posted this question a long time ago, but take a look at this property:
.class, #id, tag, * {
font-variant-numeric: lining-nums;
-moz-font-feature-settings:"lnum" 1;
-moz-font-feature-settings:"lnum=1";
-ms-font-feature-settings:"lnum" 1;
-o-font-feature-settings:"lnum" 1;
-webkit-font-feature-settings:"lnum" 1;
font-feature-settings:"lnum" 1;
}
It forces all the numerals to be correctly aligned, so you can just apply this property to * in CSS and any text containing numbers will be a lot more readable.

This code will work for Raleway, I have tested and got the result
-webkit-font-feature-settings: "lnum"; -moz-font-feature-settings: "lnum"; font-feature-settings: "lnum":

Related

How to remove the 3d effect in the font

I don't know why I am getting this 3d effect in words. How can I remove the effect and flatten the words?
The font family is Poppins
body {font-family: "Poppins";}
You can do any formatting with CSS.
a {font-style: normal;}
will make font style as normal
There may be a CSS conflict. Try this. Change class & the colors as suitable.
add
text-shadow: none;
.text-class
{
text-shadow: none;
background: #333;
color: #fff;
}

Bootstrap 4 - wildly different rendered font sizes in Ubuntu Chrome and Firefox

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 :)

Cannot resize flaticon with font-size

I am using Flaticon for a website I am developing but there seems to something wrong and I can't find out what.
I downloaded the zip file from flaticon with the option "icon font".
so I uploaded it into the my font's folder but for some reason when I link the css and put an <i class="flaticon-crowd"><i> in my html I get the icon in its default size but when I put font-size:70px; in the css it doesn't get bigger.
I can do color: #f00; and the text turns red so it's not the selector.
Also in the def tools in chrome show that the 70px font-size is used and not overruled.
Does somebody know what it could be that is causing this problem ?
thanks for your time.
Here is an example of the html I use
<!DOCTYPE html>
<html>
<head>
<!-- flaticon -->
<link rel="stylesheet" type="text/css" href="assets/css/flaticon/flaticon.css">
<title></title>
</head>
<body>
<i style="font-size: 70px" class="flaticon flaticon-crowd"></i>
</body>
</html>
Use this class in your css to change the font size.
[class^="flaticon-"]:before, [class*=" flaticon-"]:before, [class^="flaticon-"]:after, [class*=" flaticon-"]:after {
font-size: 150px;
}
Hope it will solve your issue.
A better solution would be:
[class^="flaticon-"]:before, [class*=" flaticon-"]:before,
[class^="flaticon-"]:after, [class*=" flaticon-"]:after {
font-size: 1em;
}
Then the size of the icon can be modified by other classes using font-size
This worked for me:
.flaticon-fast46::before{
font-size: 40px;}
Use the pseudo class :before to modify the icon as you want. You can apply all text properties of css to modify the icons.
.flaticon-crowd:before {
font-size: 17px;
}
Just delete the 'font-size: 20px;' found in the flaticon.css file and then you will be able to set the size you want in your css file.
It's Worked For me. Add :before after the element class which you want to use for icons.
span:before{
font-size: 50px;
}
for sure you could add !important to your css declaration
For example:
font-size:100px !important;
In flaticons.css change the default class into this:
[class^="flaticon-"]:before, [class*=" flaticon-"]:before,
[class^="flaticon-"]:after, [class*=" flaticon-"]:after {
font-family: "Flaticon" !important;
font-style: normal !important;
font-weight: normal !important;
font-variant: normal !important;
text-transform: none !important;
speak: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
the flaticon.css file contains a line that specifies the
font-size: 20px;
this applies over all the flat icons. You may delete that entry to freely edit single icons, or you can respecify a preferred icon size in that same line which will be reflected in all the icons.

font size discrepancy between tumblr and hard coded

I have an odd issue... When im comparing two elements on a website I have coded on my server compared to a tumblr site I created on their server, there is a 2px font size discrepancy.
both sites have this code:
<body>
<h1>Text</h1>
I have no font sizes set anywhere but both body css codes are:
body {
font-family: Arial;
font-size: 100%;
color: #000;
background: #FFF;
width: 4100px;
padding: 0;
margin: 0;
}
and both h1 codes are:
h1 {
font-size: 100%;
font-weight: normal;
margin: 0.67em 0 0.67em 0;
}
for whatever reason, the tumblr site has a 2px font size difference (smaller). is there any known reason why?
EDIT
I've added a base font size of 16px to both html attributes, however there still seems to be about a 2px difference. Some links to the sources:
Server:
http://goo.gl/PfyQ6r
Tumblr:
http://goo.gl/5gDfp4
Tumblr's global.css file as AR7 noted is set to 14px, the default html font size in most browsers is 16px but is also user definable.
html, body {
font-family: "Helvetica Neue","HelveticaNeue",Helvetica,Arial,sans-serif;
font-weight: 400;
line-height: 1.4;
font-size: 14px;
font-style: normal;
color: #444;
}
Your question code example sets the body font-size as inherited from its parent (html) at 100%. If you did not specify the html font-size it would inherit the browser's defined default font-size to 100%.
Font size by default is 16px I believe and is usually defined in the body.
Popular frameworks like bootstrap have the font size set as 14px in the body.
That's probably why there's a difference because the default font size is what is used when you specify 100%. Tumblr's own css files, which are completely unrelated to yours, specify it as 14px by default.

Ragged font in FontAwesome

I read some articles and stackoverflow questions about font awesome. I successfully implemented it on my website but I have one big problem with it.
Here is jfiddle
Here is the code
html:
<i class="icon-th-list font-25em"></i>&nbsp font 2.5em<br/>
<i class="icon-th-list font-2em"></i>&nbsp font 2em<br/>
css:
body {
text-rendering: optimizeLegibility;
-webkit-font-smoothing: subpixel-antialiased;
font-family: Arial;
}
.font-25em {
font-size: 2.5em !important;
}
.font-2em {
font-size: 2em !important;
}
Icons with font-size 2em etc. works perfectly but when I change font size to 2.5em the font is ragged and looks awful.
Am I doing something wrong?
Please help
You don't mention what browser(s) are causing the problem, but does anything here look better for you http://jsfiddle.net/panchroma/mYMnh/ ?
I changed the antialiasing to -webkit-font-smoothing: antialiased; and if you want to get fancy you can add a small shadow to the icon to smooth the :
.font-25em {
font-size: 2.5em !important;
text-shadow: 1px 1px 1px rgba(0,0,0,0.004);
}
Good luck!