Thread: Align 2 images
View Single Post
Old 11-15-2015, 01:07 PM   #2
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,797
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by JLius View Post
Hi all

How do I align 2 images, so they display in the center of the page, next to each other, with a little white space in between and a bit of explanatory text under each (like, 'this is an image of...')?

Many thanks!
Use a table There are others methods but with a table you'll have the two images aligned practically in any ereader. Use the following code:

1. In your .xhtml file:

Code:
  <div class="images">
    <table cellpadding="5" cellspacing="0" class="images">
      <tr>
        <td style="width: 50%"><img alt="Image" src="../Images/leopard.jpg" />This is a leopard</td>

        <td style="width: 50%"><img alt="Image" src="../Images/leopard.jpg" />This one too!</td>
      </tr>
    </table>
  </div>
Of course, your images will be different

2. In your .css stylesheet:

Code:
div.images {
    width: 80%;
    margin-bottom: 1.5em;
    margin-left: 10%;
    page-break-after: avoid;
}

table.images {
    padding-top: 1em;
    margin: 0 !important;
    text-align: center;
    text-indent: 0 !important;
    font-weight: bold;
    font-size: 0.8em; /* Change this if you want */
    font-family: serif;
}

table.images tr td img {
    width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
    vertical-align: middle;
}
Here you have a screenshot of Sigil:

Click image for larger version

Name:	Image1.png
Views:	157
Size:	163.0 KB
ID:	143753

I also attach an epub file so you can understand better the things.

Regards

EDIT: You can style the table inside the .css stylesheet but don't erase cellpadding="5" cellspacing="0" (you can change the values, no problem with that) inside the table tag because otherwise the table won't show centered in ADE.
Attached Files
File Type: epub Two aligned images.epub (78.1 KB, 110 views)

Last edited by RbnJrg; 11-15-2015 at 01:18 PM.
RbnJrg is offline   Reply With Quote