Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 01-21-2015, 09:27 AM   #1
Doctor T
Member
Doctor T began at the beginning.
 
Posts: 17
Karma: 10
Join Date: Nov 2013
Device: None
Question Centering Images

Hi!

Is there a problem if I use ...

<p class="center"><img src="../Images/Tbl_1_1.jpg" /></p>

... for centering images?

FYI, i use ...

p.center {text-align: center;}

... in the style sheet.

Thank you!

Dr. T
Doctor T is offline   Reply With Quote
Old 01-21-2015, 09:43 AM   #2
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,361
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
No problem that I know of. That's typically how I go about it. Might want to make sure your img tag has an "alt" attribute, though.
DiapDealer is offline   Reply With Quote
Advert
Old 01-21-2015, 09:46 AM   #3
Grizella
Member
Grizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a TexanGrizella might easily be mistaken for a Texan
 
Posts: 17
Karma: 18298
Join Date: Jan 2015
Device: Mantano
The alt attribute is mandantory. If there is textual replacement for the image, leave it empty (alt="")
Grizella is offline   Reply With Quote
Old 01-21-2015, 10:52 AM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,912
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
is there a plain:

p { <style stuff>; }

somewhere in your CSS

Your p.center class may need to be AFTER that in the sheet.

is it possible that there are 2 p.centers defined?
theducks is offline   Reply With Quote
Old 01-21-2015, 03:36 PM   #5
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
Also, if you have in your plain p selector text-indent, then you must also set in your center class the text-indent to zero.
Toxaris is offline   Reply With Quote
Advert
Old 01-22-2015, 05:54 AM   #6
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,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Doctor T View Post
Hi!

Is there a problem if I use ...

<p class="center"><img src="../Images/Tbl_1_1.jpg" /></p>

... for centering images?

FYI, i use ...

p.center {text-align: center;}

... in the style sheet.

Thank you!

Dr. T
That won't work because the property "text-align: center;" only works for inline elements and an image is a block element. So you have two ways to center horizontally an image:

1. To use:

Code:
.center {
     width: X%; /* Where X is the width you wish */
     margin-left: auto;
     margin-right: auto;
}
And in the .xhtml file:

Code:
<p class="center"><img alt="" src="../Images/Tbl_1_1.jpg" /></p>
Note: now "margin-left: auto" and "margin-right: auto" work in ADE 4.0 (for that reason I'm using them).

2. To use:

Code:
.center { 
      text-align: center;
      text-indent: 0;
}

.inlined {
     display: inline;
}
And in the .xhtml file:

Code:
<p class="center"><img class="inlined" alt="" src="../Images/Tbl_1_1.jpg" /></p>
Both methods will center your image.

Regards
Rubén
RbnJrg is offline   Reply With Quote
Old 01-22-2015, 07:11 AM   #7
Paulie_D
Connoisseur
Paulie_D began at the beginning.
 
Paulie_D's Avatar
 
Posts: 67
Karma: 10
Join Date: Apr 2011
Device: Kindle 3, Samsung Tab 4
Quote:
Originally Posted by RbnJrg View Post
That won't work because the property "text-align: center;" only works for inline elements and an image is a block element.
Actually, images are inline by default

http://www.impressivewebs.com/defaul...html-elements/
Paulie_D is offline   Reply With Quote
Old 01-22-2015, 07:12 AM   #8
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,361
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by RbnJrg View Post
That won't work because the property "text-align: center;" only works for inline elements and an image is a block element. So you have two ways to center horizontally an image:

1. To use:

Code:
.center {
     width: X%; /* Where X is the width you wish */
     margin-left: auto;
     margin-right: auto;
}
And in the .xhtml file:

Code:
<p class="center"><img alt="" src="../Images/Tbl_1_1.jpg" /></p>
Note: now "margin-left: auto" and "margin-right: auto" work in ADE 4.0 (for that reason I'm using them).

2. To use:

Code:
.center { 
      text-align: center;
      text-indent: 0;
}

.inlined {
     display: inline;
}
And in the .xhtml file:

Code:
<p class="center"><img class="inlined" alt="" src="../Images/Tbl_1_1.jpg" /></p>
Both methods will center your image.

Regards
Rubén
I've never had the slightest problem horizontally centering an image the way the OP described: by setting "text-align: center" on the (block element) p tag the encapsulates the image. Never had to inline the img element using css.
DiapDealer is offline   Reply With Quote
Old 01-22-2015, 08:19 AM   #9
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,181
Karma: 144286760
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
And this thread belongs in the Sigil forum and not the ePub forum because?
JSWolf is offline   Reply With Quote
Old 01-22-2015, 08:50 AM   #10
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,912
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:
Originally Posted by JSWolf View Post
And this thread belongs in the Sigil forum and not the ePub forum because?
  • The OP was viewing a book in Sigil
  • The OP was editing/creating a book in Sigil
Modern usage is:
It is the Messengers fault
theducks is offline   Reply With Quote
Old 01-22-2015, 09:48 AM   #11
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,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by DiapDealer View Post
I've never had the slightest problem horizontally centering an image the way the OP described: by setting "text-align: center" on the (block element) p tag the encapsulates the image. Never had to inline the img element using css.
Read this thread (and my posts there ):

https://www.mobileread.com/forums/sho...d.php?t=247587
RbnJrg is offline   Reply With Quote
Old 01-22-2015, 10:51 AM   #12
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,361
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
So when you said; "that won't work," you really meant; "that may not work with certain buggy rendering software"?
DiapDealer is offline   Reply With Quote
Old 01-22-2015, 05:07 PM   #13
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,641
Karma: 8566337
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by DiapDealer View Post
So when you said; "that won't work," you really meant; "that may not work with certain buggy rendering software"?
Hmmm, yes
RbnJrg is offline   Reply With Quote
Old 01-22-2015, 06:41 PM   #14
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
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:
Originally Posted by DiapDealer View Post
So when you said; "that won't work," you really meant; "that may not work with certain buggy rendering software"?
Diap:

Might be nitpicky, admittedly, BUT, for those of us stuck with covering all those bases, Ruben is correct. ;-) Juzzzzz sayin'.

Hitch
Hitch is offline   Reply With Quote
Old 01-22-2015, 07:07 PM   #15
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,361
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Hitch View Post
Diap:

Might be nitpicky, admittedly, BUT, for those of us stuck with covering all those bases, Ruben is correct. ;-) Juzzzzz sayin'.

Hitch
Oh, I don't disagree (and I appreciate the knowledge). I just thought something along the lines of; "that might give you problems on iBooks," would have been more appropriate than; "that won't work." 'Cause let's face it ... it will work a great, big chunk of the time.

Ruben's post led me to believe there was something inherently wrong with the code, is all. And I don't believe there is. The text-align css was properly being applied to the block e!ement 'p' (whose text will display inline). The img tag, as a block-level element that's displayed inline should be centered horizontally by any competent browser/epub renderer out there. But if one has to ensure that things display properly on the widest range of devices out there, then by all means... point out the aberant systems, and the special requirements to make them to behave properly.

Last edited by DiapDealer; 01-22-2015 at 07:20 PM.
DiapDealer is offline   Reply With Quote
Reply

Tags
centering images


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering images in iPad mini/iBooks/iOS8 AlexBell ePub 18 10-26-2014 12:02 AM
Centering images perkin5 Conversion 8 09-19-2014 10:40 AM
Centering Images using object styles SamL ePub 7 04-05-2011 01:28 PM
How to do centering sjohnson717 Calibre 15 02-28-2010 09:20 AM
centering images with css override? Amalthia Calibre 2 03-30-2009 01:53 PM


All times are GMT -4. The time now is 12:28 PM.


MobileRead.com is a privately owned, operated and funded community.