Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-20-2011, 04:48 PM   PM User | #1
minazfath
New Coder

 
Join Date: Oct 2011
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
minazfath is an unknown quantity at this point
center an image in CSS

Hi all,
I am new to Css ,I try to ix a image in center,but it doesn' seems to work.

main.css
-----------
Code:
img.center {
display: block;   
margin-left: auto;  
margin-right: auto; 
}
and index.php
Code:
<?php
echo 'Hallo';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<LINK REL=StyleSheet HREF="main.css" TYPE="text/css" MEDIA=screen></link>
<img src="image.png" alt="Suni" class="center" />
It doesn't work in IE but in firefox it works ,what can i do?

thankyou all.
minazfath is offline   Reply With Quote
Old 12-20-2011, 04:52 PM   PM User | #2
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Hello minazfath,
To center an element you need three things:
  1. a valid DocType
  2. an element with a width
  3. that elements right/left margins set to auto

You are right in making your image display: block; as well.
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 PM.


Advertisement
Log in to turn off these ads.