07-15-2022, 05:21 PM | #1 |
Junior Member
Posts: 8
Karma: 2139376
Join Date: May 2013
Device: none
|
Background Colors or Images
Is there a way when creating an ebook that I can have a background color or image behind my text?
|
07-15-2022, 05:38 PM | #2 |
Grand Sorcerer
Posts: 27,548
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Moving this to the EPUB forum as it's not Sigil specific at all.
|
07-15-2022, 05:47 PM | #3 |
Bibliolater
Posts: 4,762
Karma: 2600000
Join Date: Dec 2021
Location: England
Device: none
|
Take a look at Roy Glashan’s library of Epubs and look at the code he uses to give background colour - https://freeread.com.au/
|
07-15-2022, 06:53 PM | #4 | |
Wizard
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
1. In your .xhtml file: Code:
<body class="back"> <p>Your text here...end of your text</p> </body> Code:
.back { background: url("path_to_your_image_here") center center no-repeat; background-size: cover; } However, not all ereaders support a background image. For example the ereader Overdrive, so far, it doesn't do it (I suppose is due to a bug). In those cases, you could try working with the properties "position: realtive" and "z-index" and positioning image and text with the "top" and "left" properties, something like this: Code:
<p class="first"><img alt="" src="path_to_your_image_here" width="100%"/></p> <p class="second">Your text here...end of your text</p> Code:
.first { position: relative; z-index: 0; left: 0; top: 0; } .second { position: relative; z-index: 1; left: 0; top: -XXXpx; /* where XXX is the height in px of your image */ } Finally, the last method that I know, is by using a negative margin-top: Code:
<p><img alt="" src="path_to_your_image_here" width="100%"/></p> <p class="text_over">Your text here...end of your text</p> Code:
.text_over { margin-top: -XXXpx; /* where XXX is the height of your image */ } For the case of a background color, that is elementary, just create a class like: Code:
.red { background: red; /* or #ff0000 or rgb(255, 0, 0) */ } Code:
<p class="red">Your text here...end of your text</p> Last edited by RbnJrg; 07-15-2022 at 07:01 PM. |
|
07-16-2022, 08:24 AM | #5 |
the rook, bossing Never.
Posts: 11,154
Karma: 85874891
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
But consider if it's a good idea. Usually it's not.
|
07-16-2022, 08:29 AM | #6 |
A Hairy Wizard
Posts: 3,094
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
I am working on a series of books now (web blog type) where the author chose to use font color for different speakers/meanings. It works well when you have a darker background but some of the lighter colors are almost unreadable if you have a white background so I had to force the background to a darker color using the <body> tag.
CSS: Code:
body {background-color:black} It worked fine on my device, but it is definitely NOT recommended on an e-ink because it tends to make it almost unreadable. Maybe look at some media queries to handle this. Also, I'm not sure if Amazon has a rule against putting a color in the <body> like they do with the font??? You may want to check that as well. However, even if you put that styling in there the device/app might not honor the publishers CSS... some of them ignore it completely in favor of their internal styling, some will ignore parts of the CSS. If you want to "force" the background-color you can put it as an inline style (not something I normally recommend doing...it makes my tummy curdle just thinking of it...) on just the body/div/p you really need using: Code:
<body style="background-color:black"> <div style="background-color:black"> <p style="background-color:black"> Last edited by Turtle91; 07-16-2022 at 08:36 AM. |
07-16-2022, 04:45 PM | #7 |
Resident Curmudgeon
Posts: 73,957
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
If there's a chance this ePub will be read on an eInk screen, don't do it with a background color or image. It will most likely not work well.
|
07-18-2022, 04:32 PM | #8 | |||
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
HTML: Code:
<div class="red"> <p>This is going to have a red background.</p> </div> <p class="blue">This is a blue background too.</p> Code:
div.red { background-color: red; } p.blue { background-color: blue; } It would be good to know WHY bbacle is trying to get a color/image as the background... then we can give more details. Quote:
For all the details, see this previous discussion: Quote:
If you do use colors, you have to be very careful with contrast between font+background color. And remember, people do read using things like Night Mode. For more info on that, see: And if you want to see the "colored box" CSS I used way back when, you can see: Not much has changed on that front. |
|||
07-18-2022, 07:17 PM | #9 | |
Wizard
Posts: 1,542
Karma: 6613969
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
|
|
07-18-2022, 08:09 PM | #10 | |
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
I tend to avoid many of the shorthands, like margin, and instead specify all 4 margins separately (if needed). I believe it's more human-readable, instead of having to decipher EXACTLY what variables are what. Examples from "margin" at MDN: Code:
/* Apply to all four sides */ margin: 1em; /* vertical | horizontal */ margin: 5% auto; /* top | horizontal | bottom */ margin: 1em auto 2em; /* top | right | bottom | left */ margin: 2px 1em 0 auto; Code:
blockquote { margin-top: 1em; margin-bottom: 2em; } When you have it fully typed out, there's no confusion there. |
|
07-19-2022, 04:26 AM | #11 | |
Resident Curmudgeon
Posts: 73,957
Karma: 128903250
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
Tags |
background, ebook |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Different colors für Background and Page | GeorgiusT | Viewer | 2 | 10-05-2021 10:58 AM |
Color of background makes colors hard to see | ChipAHoy | Library Management | 1 | 01-14-2021 10:49 PM |
Troubleshooting New to Kindle...can I invert the text/background colors? | sydmalicious | Amazon Kindle | 9 | 03-13-2020 05:42 PM |
Change the background colors of the columns? | slg-bug | Library Management | 2 | 07-08-2016 03:50 PM |
Can not convert epub background and foreground colors to AZW3 | ronaldl | Conversion | 1 | 01-14-2014 09:53 PM |