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>
Related
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>
Text figures, as Wikipedia calls them, are something that sometimes makes text more readable. Normal-sized numbers usually stand out much more than the rest of the text. Especially in text that is in small-caps, the big numbers don't fit that well. How would I have smaller numbers in text using CSS?
An example of where I'd like to have smaller numbers:
.smallcaps {
font-variant: small-caps;
}
<p class="smallcaps">Example smallcaps 1337 text.</p>
<p>Another text with 42 numbers in it.</p>
What you are asking for are sometimes called "lowercase numerals" but, among typographers, are most often called "old style numerals" or "old style figures". That's what they're called in OpenType.
Some fonts support old style figures by default and some support them as alternate glyphs. In OpenType fonts that support them as alternate glyphs, they would be selected by activating the 'onum' feature.
In CSS, when using a font that supports oldstyle figures via the 'onum' feature, these can be selected using font-variant-numeric: oldstylenums. See https://www.w3.org/TR/css-fonts-4/#font-variant-numeric-prop for reference.
You can change text (numbers) size with css font-size property and span tag.
Like this :
.smallcaps {
font-variant: small-caps;
}
.num {
color :red;
/* font-size: smaller; */
/* font-size: x-small; */
font-size: xx-small;
}
<p class="smallcaps">Example smallcaps <span class="num">1337</span> text.</p>
<p>Another text with <span class="num">42</span> numbers in it.</p>
<p class="smallcaps">Example smallcaps 1337 text.</p>
<p>Another text with 42 numbers in it.</p>
So I have a some text "only 3 days left"
Which I what to make the color #EF5F3C
and also to made bold too. An to ignore the styling for the rest of sentence.
Image example of what I am trying to acheive:
I have tried using multiple inline style to style the HTML which does work for colour, font-size etc but not strong or em.
<div class="copy">
<h6> <span style="color:#EF5F3C;"><strong>Only 3 days left</strong></span> to fund this project</h6>
<p>Join the <strong>42 </strong> other donors who have already supported this project. Every dollar helps</p>
</div>
The h6 is already bold by default.
I made and example where you can see it with h6 and a regular paragraph p tag.
h6 span {
font-weight: bold;
color: #EF5F3C;
}
p span {
font-weight: bold;
color: #EF5F3C;
}
<h6><span>Only 3 days left</span> to fund this project</h6>
<p><span>Only 3 days left</span> to fund this project</p>
Say we have a text paragraph (p, div or what have you):
Be nice. The world 🌎 is a small town 😄
I would like the text in it to be italic, but emoji to have a normal font-style without wrapping the emoji or any other text in additional tags.
Be nice. The world 🌎 is a small town 😄
<p><i>Be nice. The world</i> 🌎 <i>is a small town</i> 😄<p>
In my opinion, better way is to wrap emoji icons in an inline element like <span> and style in css.
.emoji {
font-style: normal;
}
p {
font-style: italic;
}
<p>Be nice. The world <span class="emoji">🌎</span> is a small town <span class="emoji">😄</span></p>
the simplest way is :
<p><i>Be nice. The world</i> :) <i>is a small town</i> :P </p>
alternatively you can use css to style.
You can use any of these
x{
font-style: italic;
}
span{
font-style: italic;
}
<p><x>Be niceThe world </x> ☎ <x>is a small town </x> ☎</p>
<p><span>Be niceThe world </span> ☎ <span>is a small town </span> ☎</p>
I have a really hard time getting some kind of good looking vertical text for my ribbons.
As you can see on the link
http://madbogen.com/
The first ribbon have some white text printed on the image. Is there any possible way to achieve this with CSS? Or is it enough if i just label the a-tag with a title according to what it says - I'm thinking searching etc?
I hope to achieve to same effect without using title so I can get rid of the little box coming up when hovering the ribbons.
Thanks in advance
You could use <br /> tags to stick them onto separate lines like so:
<div>
<span>H <br />E <br />L <br />L <br />O <br />! <br />
</span>
Demo here:
http://jsfiddle.net/QSByU/497/
Or alternatively you could wrap each letter in a span tag like so:
<h1>
<span> N </span>
<span> E </span>
<span> T </span>
<span> T </span>
<span> U </span>
<span> T </span>
<span> S </span>
</h1>
Demo here:
http://jsfiddle.net/QSByU/498/
There are lots of other methods that you can use to make text appear vertically (see http://code.tutsplus.com/tutorials/the-easiest-way-to-create-vertical-text-with-css--net-15284).
Thanks guys. I looked at tutsplus website and found letter-spacing and word-wrap to be what I needed.
color: white;
font-size: 16px;
word-wrap: break-word;
text-align: center;
padding-left: 15px;
padding-top: 45px;
letter-spacing: 28px;
text-decoration: none;
line-height: 105%;
font-style: normal;
font-family: "Times New Roman";