![]() |
#1 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Nov 2019
Device: Apple Ipad
|
Em Vs Percentage
Dear All,
I need some clarification about the value of percentage to em. For example if we declare the value in css 10% it's equal to 3em? Please let me know the exact value of percentage to em. If any converter available in website. Kindly check and advice. Thanks, Joseph Jayaseelan D. |
![]() |
![]() |
![]() |
#2 |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73,936
Karma: 315160596
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Oasis
|
CSS percentages usually reference the width (or height) of the display area.
The em measure is relative to the font size. There's no relationship between percentage and em at all. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
mostly an observer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,519
Karma: 987654
Join Date: Dec 2012
Device: Kindle
|
In the lead-type days, an em was the width of a capital letter M. That's no longer true, but it's good enough to go by. My style sheet uses ems to designate paragraph indents (1.5 em), blocks of text (1 em), and margin-top and margin-bottom (usually 0.0 em but that can vary).
I use percents to designate font size (200% for the paragraph style for the book title, 150% for chapter heads and the paragraph style for the subtitle, 125% for sub-heads and the paragraph style for author and publisher). https://notjohnkdp.blogspot.com/2013...yle-sheet.html |
![]() |
![]() |
![]() |
#4 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,347
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Here's a short discussion on the differences: CSS Font-Size: em vs. px vs. pt vs. percent
There is some benefit to working in percent, but as long as you set the font size in % in the <body> then ALL other (font-size) references can be made in EM to keep them relative to each other regardless of screen size. eg: Code:
body {font-size:100%} p {font-size:1em} h1 {font-size:1.5em} h2 {font-size:1.3em} h3 {font-size:1.2em} h4 {font-size:1.1em} Last edited by Turtle91; 11-27-2019 at 04:13 PM. |
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,762
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
h1 { font-size: 200%; } Code:
h1 { font-size: 2em; } |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#7 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Code:
p {font-size: 1em} h1 {font-size: 2em} h2 {font-size: 1.5em} h3 {font-size: 1.17em} h4 {font-size: 1em} h5 {font-size: .83em} h6 {font-size: .67em} |
|
![]() |
![]() |
![]() |
#8 | |
The Grand Mouse 高貴的老鼠
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 73,936
Karma: 315160596
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Oasis
|
Quote:
In which case 1em = 100%, 0.5em = 50%, etc. |
|
![]() |
![]() |
![]() |
#9 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,762
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Not at all. I see you didn't test what I wrote; do the try and you'll see that your statement is wrong. A font-size of 200% for h1 is exactly the same as a font-size of 2em.
EDIT: Here you have an epub so your tests will be easier. And here you can also watch an screenshot: with Code:
.percent { font-size: 400%; } .ems { font-size: 4em; } Code:
<h1 class="percent">TITLE in %</h1> <h1 class="ems">TITLE in ems</h1> Last edited by RbnJrg; 11-28-2019 at 08:12 AM. |
![]() |
![]() |
![]() |
#10 | |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,347
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Quote:
As RbnJrg mentioned, is not correct. h1 might have a 2em default value, but when you specify a value in css then it over-rules any default value - it does not multiply the default value. |
|
![]() |
![]() |
![]() |
#11 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 878
Karma: 2457540
Join Date: Nov 2011
Device: none
|
|
![]() |
![]() |
![]() |
#12 | ||
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#13 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,347
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
The W3 CSS specification doesn't define a "default font size" (other than initially "medium"). Any browser/reader/app could have different defaults - however most browsers use 16px=1em=100% and they most commonly use the sizes JSWolf mentioned in absence of a user defined style.
Because different browsers/apps/readers could use a different default size it is beneficial, for consistency's sake, to define your document baseline in the document itself. Thus "body {font-size:100%}" or "body {font-size:120%}", etc. Then all other font-sizes can be set relative to that size using em. Doing it this way allows the document font sizes to be consistent relative to the other font sizes in that document regardless of the font-size (zoom level) selected by the user. The actual font-size you select can be anything you want, and can be independent of the heading number selected. eg (for example) all of these combinations are acceptable (although IMHO funny looking): Code:
p {font-size:.5em} h1 {font-size:6em} h2 {font-size:5em} h3 {font-size:4em} h4 {font-size:3em} h5 {font-size:2em} h6 {font-size:1em} p {font-size:3.5em} h1 {font-size:2em} h2 {font-size:2em} h3 {font-size:2em} h4 {font-size:2em} h5 {font-size:2em} h6 {font-size:2em} p {font-size:.75em} h1 {font-size:1em} h2 {font-size:2em} h3 {font-size:3em} h4 {font-size:4em} h5 {font-size:5em} h6 {font-size:6em} p {font-size: 1em} h1 {font-size: 2em} h2 {font-size: 1.5em} h3 {font-size: 1.17em} h4 {font-size: 1em} h5 {font-size: .83em} h6 {font-size: .67em} Last edited by Turtle91; 11-28-2019 at 03:10 PM. |
![]() |
![]() |
![]() |
#14 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
If you use % for space such as margin-top: 5%, that space will differ depending on the screen size. Using margin-top: 3em will be the same with different screen sizes if the font size is the same.
|
![]() |
![]() |
![]() |
#15 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 755
Karma: 7025494
Join Date: Aug 2017
Location: Italy
Device: Kindle Paperwhite, Kobo Elipsa, Pocketbook Inkpad 4, Inkpad Color
|
Quote:
![]() ![]() ![]() |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Percentage in IBooks | Klippy | Apple Devices | 2 | 06-18-2015 03:29 PM |
Percentage Read | ParadiseLost | Calibre | 1 | 04-07-2013 11:24 PM |
Problem with Percentage Measurements | verydeepwater | Kindle Formats | 5 | 02-19-2013 11:08 AM |
Percentage of all books sold | jbcohen | News | 11 | 04-24-2012 06:08 PM |
Percentage of Readers | patrickt | General Discussions | 44 | 09-08-2010 10:01 AM |