View Single Post
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,659
Karma: 205039118
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