after spending several hours yesterday trying to find that drop cap thread i knew i had seen before i thought it might be nice to have ONE thread where we can all post WORKING code snippets that have been tested, for specific effects or workarounds, so that they are easy to find and use by everyone.

please mention briefly the function of the code (i.e. "Drop Caps") and give the (x)html code and the css code, and a link to the original thread if there was a discussion about the problem.

to start with, here is the drop cap code from this thread (thanks jellby, peter sorotkin, brewt, llasram, kovid, and everybody else who worked on this tricky problem !!)

To force the second paragraph to start below the drop cap, when the first paragraph is short.

The "white-space: pre;" part of span.first is needed for cases where there is a space between the drop cap and the start of the line, as in "<span class="drop">A</span><span class="first afterA"> day after</span>", since otherwise the space beginning the span.first is dropped (take care with linebreaks inside this span.first).

A similar "afterL" class can be needed. If the drop cap is not A or L, use only class="first".

When there is some punctuation before the drop cap, this code may be useful:

Novels often have fragments of poetry or songs interspersed in them. As we all know, poetry has some formatting requirements (hard line breaks) and some display customs (centered or indented block).

I use code like the following when I have to format poetry fragments in a text. I use individual <p></p> for each line instead of just <br/> because I want to use the effect of the negative parindent: when a line is too long to fit the screen, it is "soft-broken" and the second portion is indented farther to the right (actually, I'd like it to be left-aligned and preceded by "[", but I don't think that's possible)

So, use class="first" when a new stanza begins and class="indented" for indented lines.

For pieces with more complex indent pattern or for mainly poetry works I'd probably do something different, like a <div></div> for each stanza (which could include "page-break-inside: avoid" in the css).

#5 zelda_pinwheel 05-10-2009, 06:28 PM

i've been looking at the adobe sample ebook of Alice in Wonderland (attached). in chapter 6, they've managed to reflow text around a non-rectangular image :

i've been wanting to figure out how to do that for ages and it turns out it's laughably easy. here's the code :

Code

<p><div style="float:left;max-width:170px;width:8.5em;text-align:left;
margin:0.25em 0px 0.25em 0.25em">
<img style="display:block;max-width:342px;width:17em;"
src="images/alice23a.gif" alt="Alice talks to Cheshire Cat"/>
</div>
<div style="float:left;max-width:170px;width:8.5em;max-height:220px;
height:11em;margin:0.25em 0.25em 0.25em 0px"/> So she set the little creature down, and felt quite relieved to
see it trot away quietly into the wood.
(...)
when she was a little startled by seeing
the Cheshire Cat sitting on a bough of a tree a few yards off.
</p>

open a paragraph. create 2 floated divs.div 1 : define the width** as the width of the narrow leg of the image. place the image inside the div, and define the img width** as the actual width of the entire image.div 2 : define the width** as the actual width of image, and define the height as the height of the wide part of the image. this div is an empty placeholder.place text in paragraph following divs.

**notice the width is given as max-width in pixels (actual size of the image) and also in ems ; this allows the images to be resized with the text if text size is enlarged or reduced.

the 2 divs stack on top of each other and the text wraps around them, first the wide one, then the narrow one. the image overflows its narrow div and is visible beside the text.

this will work for left or right side images (just define the float accordingly) with a shape of an upside down L. i imagine it should be possible to make it work for an image with the large bit on the bottom (like a right side up L) but i've not yet tried it out. maybe it would take a third narrow div and add a "clear" to the wide one, to push the wide one down... there might even be other ways to use this idea.

Oh, gosh, let's not argue here - the reference is for how to create a DROP CAP for an EPUB using WORD, as opposed to Amaya or Dreamweaver or Notepad. A specialty snippet of a workable css that also happens to work in Word with a coupla caveats.

This is such a useful thread Will this be collated for the wiki once everyone has revealed their deepest darkest css secrets?

#10 zelda_pinwheel 05-12-2009, 10:08 AM

Quote brewt

Oh, gosh, let's not argue here - the reference is for how to create a DROP CAP for an EPUB using WORD, as opposed to Amaya or Dreamweaver or Notepad. A specialty snippet of a workable css that also happens to work in Word with a coupla caveats.

yes, agreed. everyone has their own workflow, some people may find this really useful. it is for epub, so it seems fine to have it in this thread.

Quote Kirtai

This is such a useful thread Will this be collated for the wiki once everyone has revealed their deepest darkest css secrets?

that is an excellent idea, and we don't have to wait until all is revealed ; we could start it now. would you like to do the honours ?