View Single Post
Old 12-06-2010, 03:07 AM   #5
toddos
Guru
toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.toddos ought to be getting tired of karma fortunes by now.
 
toddos's Avatar
 
Posts: 695
Karma: 822675
Join Date: May 2010
Device: Kobo Aura, Nokia Lumia 920 (Freda)
Wow, that's about the most convoluted method I've ever heard of for fixing simple CSS issues

There are three ways you can go about doing this:
  1. Use Calibre's "Tweak epub" option. This will expand the epub and open the temporary folder where the epub was expanded. Open the .css file (there should be only one) in your favorite text editor (or Notepad, if you have nothing else) and then look for any "margin-left" or "margin-right" entries.
  2. Use an epub editor like Sigil. You can open the file directly from Calibre's storage folders. Use the "Open containing folder" option (shortcut key: O) to find the path to the folder, and then open the epub from that location in Sigil. As in 1, find the .css file in the list of files on the left in Sigil, and then look for any "margin-left" or "margin-right" entries.
  3. Since epub is just a zip file renamed, you can do this manually as well. Go to the containing folder location (see 2 above), rename the .epub file to .zip ("foo.epub" would become "foo.zip"). Open this file with your favorite zip tool (or Windows Explorer) and extract the contents including all folders to a temporary working directory. Find the .css file and follow the rest of 1 above. When done, zip up all of the files/folders in the temporary folder (do not zip up the folder itself -- when you look at the final zip, the files should be at the root level), give it the same name as the original zip file, and then rename the extension back to .epub and copy it into Calibre's folder structure. It's probably best to keep a backup of the original epub until you've verified that your new one works.

Within the CSS file, my solution to margin problems is generally to remove the lines entirely. If I want any margins, I'll let Calibre add them on convert (usually go with 5pt all around). Also, make sure you don't accidentally remove any intentional indentation margins, such as for blockquote-type text. Unfortunately this is pretty difficult to do without context, since the class names are never descriptive (calibreN, where N is a number). This is why I like using option 2 above. I can search for a class name across all files in the epub and see where it's being used. From that, I can get enough context to understand what the class is intended to do, and thus whether or not I should remove margins.

Also note that this assumes all styles are put into a separate .css files. Most (all?) calibre conversions should not have any inline styles, but if you're working with a non-calibre-created epub (for example, an epub you've purchased from a store and liberated) you might find that some styles have been sprinkled around the HTML code. If this happens, you're basically screwed. You'll have to go through every single HTML file in the epub and verify that the inline styles are correct.
toddos is offline   Reply With Quote