[HTML] How To Align Any Image Center !

Status
Not open for further replies.

Rapid S

Active Member
912
2010
7
0
You dont know how to align images @ center ?
today i will teach you :)

:)

A Simple Img Code to align it to left
PHP:
<img src="http://www.wjunction.com/images/logo.png">
To Align The Image to Center use this code
PHP:
<center><img src="http://www.wjunction.com/images/logo.png"></center>
hope i have explained well (although this was my first tutorials)


=========================

A better way is to use DIVs and CSS and auto the margin:
PHP:
margin: auto;

Above Code Is Suggested By jayfella
 
28 comments
well using align=center doesnt always work in all browers. Its really picky - it will work sometimes, and not at other points in the page. Using auto margins is completely cross-browser compatible.

Using <center> is fine, but you should really put as many variables in the CSS as possible, so you dont have to edit any html/php files and easily make any necessary changes via CSS.
 
<center> isn't advised. It's not html 5 compliant either any more if I remember correctly. I believe it's being dropped in favor of css as show by jayfella. I know your probably not using html 5 now but you may as well learn for the future.

EDIT: lol hot topic for a <center> topic :D

[slide]http://screensnapr.com/u/v3dhos.png[/slide]
 
to be honest i ahve never used the <centre> in my codings i would prefer to do in CSS

Code:
.left{
    float:left;
}
.right{
    float:right;
}
.acentre{
    text-align:centre;
}

Then in my html use like

Code:
<div class="left">
   <img class="acentre" src=",..."/>
</div>

You save so much time if you use classes t o store your design parameters
 
u can use tables if u want :s
<table width=100%><tr><td><img src="blahblah.jpg"></img></td><tr></table>
you can use height=100% too if u want it to be in the center of the page..! however it is not compatible with some versions of IE
 
Tables are CPU chompers - only use when absolutely necessary, and its a really bad idea to use in loops - and yeah your right elj, just assumed there would already be a wrapper since most people will be editing existing themes.
 
Tables are CPU chompers - only use when absolutely necessary, and its a really bad idea to use in loops - and yeah your right elj, just assumed there would already be a wrapper since most people will be editing existing themes.
was just giving an alternative :) xD
Thanks for the info btw
 
Yea man - thats what this area is all about. Exploring alternatives and learning along the way - nobody knows everything - hell - Hyp and el_j have shown me that already - but its the wise man that willingly accepts it, and the sore-headed that continues to be head-strong.
 
The center element is deprecated in HTML 4.01 and XHTML. Btw Skords, using tables for layout is again deprecated and certainly not recommended (also cuz of CPU hogging, as Jay mentioned). ;)

Thanks for the info Jay and ELJ. :) And also Rapid S, for making this thread. :P
 
Status
Not open for further replies.
Back
Top