![]() |
#1 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
CSS question: breaks and indents
Hi everybody I'm a css and epub beginner.
My source consists of many continuous blocks of text whose paragraphs are marked by an indent. I wanted the first paragraph each block to be un-indented so I added some css Code:
p { margin: 0; } p + p { text-indent: 1em; } I found a solution already which is to wrap all the break tags in div tags, but my question is: is this a reasonable solution? What is the normal approach? Should all of these blocks be contained by tags? Should I add a class to every first paragraph of every block that follows another? Thanks for any tips |
![]() |
![]() |
![]() |
#2 |
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
|
Adding all those tags will work but it is not considered "in good form"... and it is a whole heck of a lot of work...lol
Flightcheck is telling you it doesn't like <br /> all by itself...it needs to be wrapped in a different tag <p><br /></p> or <div><br /></div>...but there is a much better way to organize your paragraphs: Let Sigil wrap each paragraph in a paragraph tag - that's what they are for. Don't use <br /> tags to give spaces between paragraphs. Then you can style the paragraphs however you want using a CSS stylesheet. For example: Code:
<p class="first">This is the first paragraph. It has a zero indent on the first line.</p> <p>This is the second paragraph. It has a 1.2em indent by default.</p> <p>This is the third paragraph. It has a 1.2em indent by default.</p> <p>This is the fourth paragraph. It has a 1.2em indent by default.</p> CSS: p {text-indent:1.2em} p.first {text-indent:0} You can further style your paragraphs with extra space and no indent (eg a scene break in a chapter) by giving it it's own class: Code:
<p class="SecBrk">This is the first paragraph after a scene break. It has a zero indent on the first line and extra space before the paragraph.</p> <p>This is the second paragraph. It has a 1.2em indent by default.</p> CSS: p.SecBrk {text-indent:0; margin-top:2em} The final product would look something like this: Code:
<p class="first">This is the first paragraph. It has a zero indent on the first line.</p> <p>This is the second paragraph. It has a 1.2em indent by default.</p> <p>This is the third paragraph. It has a 1.2em indent by default.</p> <p>This is the fourth paragraph. It has a 1.2em indent by default.</p> <p class="SecBrk">This is the first paragraph after a scene break. It has a zero indent on the first line and extra space before the paragraph.</p> <p>This is the second paragraph. It has a 1.2em indent by default.</p> <p>This is the third paragraph. It has a 1.2em indent by default.</p> <p>This is the fourth paragraph. It has a 1.2em indent by default.</p> CSS: p {text-indent:1.2em} p.first {text-indent:0} p.SecBrk {text-indent:0; margin-top:2em} Cheers! Last edited by Turtle91; 09-26-2015 at 06:57 PM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
You could include it inside the last </p put it in a <div pair to prevent tripping your p+p, that might be unnecessary as the div needs to just contain a nbsp for a 1 liner break or turtle91 style it ![]() CSS control . < I like this one. I am not trying to save a few dozen bytes |
|
![]() |
![]() |
![]() |
#4 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
OK thanks, I think that’s cleared it up for me.
The p.scenebreak approach is best. theduck: I see that nbsp inside <div> before </p> works as you say, That makes it a little neater. Incidentally I’m gonna stick with the <div> approach for this project. I’m correcting paragraph structure in Sigil’s book mode. Ctrl+return splits the paragraph and inserts <p><br /></p> - and I can find/replace or regex this into shape when I’m done. I would use the other approach if there was a customisable keystroke to modify the <p> tag like the header keystrokes do. Clips won’t work quite like this unless I’m mistaken. |
![]() |
![]() |
![]() |
#5 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
in fact I could even use regex to modify the <p> that follows the <p><br /></p>. Best of both worlds!
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,743
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
![]() |
![]() |
![]() |
#7 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
What I have in mind is to use the break inserted by sigil (<p><br /></p>) as a marker to locate the paragraphs that follow it and add a class to their <p> tag, the marker is then deleted. Is this what you mean?
something like Code:
<p><br /></p>[^<]*<p\b[^>]*> replace with: <p class=“scenebreak”> |
![]() |
![]() |
![]() |
#8 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,743
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
If you have... <p><br /></p> <p>Some paragraph text.</p> then it would be best to be... <p class="scenebreak">Some paragraph text.</p> That would make the code even neater and would mean that you can also include a text indent of 0. |
|
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,070
Karma: 91577715
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
the regex I posted produces that, it selects the marker and the following opening <p>, and replaces the lot with <p class="scenebreak">, the rest just remains in place ("some paragraph text</p>")
|
![]() |
![]() |
![]() |
#11 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,743
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
My mistake. But it is bad form and poor code to use a <br/> between paragraphs or even as a section break.
|
![]() |
![]() |
![]() |
#12 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,743
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
<p><br /></p>[^<]*<p\b[^>]*> <---incorrect <p><br /></p>[^<]*<p> <---correct You do not want to replace the following <p> willy nilly if hit has a class. You want to only replace the br line and the p only if the <p> is just a plain <p>. If it has a class and you want to replace the p and the class, run the regex again specifying the specific class. Then you can see if you have any more br lines left and how you want to deal with them. |
|
![]() |
![]() |
![]() |
#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
|
Quote:
Wow! For a CSS/ePub beginner your reg-fu is strong! ![]() |
|
![]() |
![]() |
![]() |
#14 |
Member
![]() Posts: 11
Karma: 10
Join Date: Sep 2015
Device: kindle 4g
|
JSWolf: Thanks, you're right. I should run a search for <p[^>] first before I do anything anyway.
Turtle91: Thanks. I've already left a swathe of destruction behind me in my short career. |
![]() |
![]() |
![]() |
#15 | |
Bookmaker & Cat Slave
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,503
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
|
Quote:
Hitch |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
ADE breaks CSS --> CSS Validation: Parse Error / Value Error | dasboeh | ePub | 4 | 12-10-2012 03:25 AM |
PML to EPUB - indents and scene breaks | snarkophilus | Conversion | 1 | 12-26-2011 01:02 PM |
Indents not working + CSS styles missing | virtual_ink | ePub | 1 | 07-04-2011 07:41 AM |
CSS for line breaks after dashes? | JaneFancher | Sigil | 4 | 04-05-2010 12:18 PM |
convert to lrf : paragraph indents, line breaks | karo02 | Calibre | 4 | 01-27-2009 09:19 AM |