Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-20-2024, 01:33 PM   #1
foosion
Addict
foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.
 
Posts: 356
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Padding v margin?

As I understand it, the basic difference between padding and margin is that margin is adding space around an element and padding is adding space within an element.

I don't understand how the difference works for things such as p and h1 with pure text (no borders, decoration, etc.). When I compare, for example, "margin: 1em" to "padding: 1em" in a p or h1 definition, the padding takes up a bit more space. Why is this?

I've looked at a few tutorials, which usually have some variation of what I wrote in the first paragraph and apply padding v margin to things which have borders, in which case the around v. within difference makes more sense.

Why the difference I'm seeing for normal text? As is often the case, I feel I'm missing something simple.
foosion is offline   Reply With Quote
Old 09-20-2024, 01:47 PM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,186
Karma: 18843349
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
margin tends to give space around the container, padding gives space within the container. Mostly noticeable when you are dealing with borders for example. However sometimes margin can be eaten by the renderer.

The box model diagram is the best thing to study for understanding...but it seems you got that. Application is just experience.
Turtle91 is offline   Reply With Quote
Advert
Old 09-20-2024, 01:56 PM   #3
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 75,917
Karma: 134368292
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
In some cases, when you use a page break command to split a page, using a margin to have some top stop on the split may not work. Padding will work.
JSWolf is offline   Reply With Quote
Old 09-20-2024, 02:00 PM   #4
foosion
Addict
foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.
 
Posts: 356
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by Turtle91 View Post
margin tends to give space around the container, padding gives space within the container. Mostly noticeable when you are dealing with borders for example. However sometimes margin can be eaten by the renderer.

The box model diagram is the best thing to study for understanding...but it seems you got that. Application is just experience.
I believe your first paragraph is essentially what I wrote above. Is that right?

What's the container for a normal text paragraph?

If I'm reading your entire post correctly, including "margin can be eaten by the renderer" the major difference is that the renderer can shrink margins (but either not padding or they don't shrink padding as much) and that's why I'm seeing, for example, a 1em padding as taking more space than a 1em margin, at least in the Calibre editor (which is where I'm looking).
foosion is offline   Reply With Quote
Old 09-20-2024, 02:07 PM   #5
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,186
Karma: 18843349
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
That is correct. The box model works for any element in HTML, including the <p>...you may see some used more effectively than the <p>, but it is there...

Here is a tutorial page for anyone else who is interested, but it seems you got the hang of it.
Attached Thumbnails
Click image for larger version

Name:	css-box-model.png
Views:	31
Size:	16.4 KB
ID:	210915  
Turtle91 is offline   Reply With Quote
Advert
Old 09-20-2024, 02:29 PM   #6
foosion
Addict
foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.
 
Posts: 356
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Just to make sure I understand, margin and padding should work the same around normal text (p, h1, etc.), but some ereaders might treat them differently.

For example, in a pure text document if I want a heading which starts a page to be separated a bit from the top of the page and the paragraph which follows it, I'd normally use:

Code:
h1 {
  font-size: 1.5em;
  margin: 0.5em 0;
  line-height: 1.2em; /* reduce space between lines if text wraps */
}
I could have used padding instead of margin, but it might have a different appearance depending on the ereader.

I'd guess conversion to kepub and how the reader renders that might also cause differences.

Last edited by foosion; 09-20-2024 at 02:31 PM.
foosion is offline   Reply With Quote
Old 09-20-2024, 02:46 PM   #7
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,533
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Margins are combined/collapsed, padding is not. A div with bottom-margin:2em followed by a div with top-margin:1em will have 2em spacing between their contents (the largest margin survives). The same with padding will result in 3em spacing (they're just added). If there are borders, margin goes outside, padding goes inside.
Jellby is offline   Reply With Quote
Old 09-20-2024, 02:58 PM   #8
foosion
Addict
foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.foosion is an enigma wrapped up in a mystery.
 
Posts: 356
Karma: 41524
Join Date: Sep 2011
Device: Kobo Libra 2 & Clara BW
Quote:
Originally Posted by Jellby View Post
Margins are combined/collapsed, padding is not. A div with bottom-margin:2em followed by a div with top-margin:1em will have 2em spacing between their contents (the largest margin survives). The same with padding will result in 3em spacing (they're just added). If there are borders, margin goes outside, padding goes inside.
That makes sense and could account for the difference if there's a div margin.

In my test case, there's no explicit div. If what I read is correct, the default margin, padding and border for div is 0.

I tried surrounding a chapter with <div> ... </div> (just inside body) and defined div as margin; 0. It didn't make any difference (as it shouldn't, based on the default).
foosion is offline   Reply With Quote
Old 09-21-2024, 02:45 AM   #9
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,533
Karma: 19000001
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
body, html and @page could all have margins (default or defined) that might be collapsed with other element margins. Depending on the reading application, you can set custom page margins that could be internally implemented as one of those, or something else. For debugging purposes, you could add some thin borders to better see your boxes.
Jellby is offline   Reply With Quote
Old Today, 03:53 PM   #10
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,378
Karma: 58053698
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Many devices control Margins (ignore publishers style version)
I use Padding to sneak past that roadblock
theducks is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
top margin padding in Apple Books kaiaua ePub 21 05-24-2020 03:20 PM
CSS: Margin vs. Padding ButWhy Workshop 6 07-31-2015 12:55 PM
Top-margin (bottom-margin?) for Kobo? Notjohn Sigil 14 02-28-2015 06:43 AM
CSS: margin-top and margin Leonatus ePub 16 06-16-2014 04:29 AM
calibre ignore margin-top and margin-bottom bender Calibre 2 12-11-2009 06:58 AM


All times are GMT -4. The time now is 11:54 PM.


MobileRead.com is a privately owned, operated and funded community.