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 01-20-2008, 06:30 PM   PM User | #1
Bob42
Regular Coder

 
Join Date: Jul 2007
Posts: 100
Thanks: 1
Thanked 0 Times in 0 Posts
Bob42 is an unknown quantity at this point
centering img in css

I'm trying to find an efficient way for centering hyperlinked images in CSS. I wan this way to work with IE, firefox, and opera. I can easily use the <center> element, but XHTML 1.0 Strict doesn't support that.

Code:
.newspost img {
display:block;
margin-left:auto;
margin-right:auto;
border:0px;
text-align:center;
}
Right now that's what I use. The problem with that is that when I'm trying to put two or more images next to each other, the second image just moves onto the next line right underneath the first image. Is there a better way of doing this?
Bob42 is offline   Reply With Quote
Old 01-20-2008, 06:54 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 Bob42,

margin:0 auto; should work for centering one image. When your putting 2 images side by side you are no longer centering an image... you'll have to do something different than your margin:0 auto;

Try float:left; on both images and adjust the positions with margin.
__________________
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
Old 01-21-2008, 03:19 PM   PM User | #3
Actinia
Regular Coder

 
Actinia's Avatar
 
Join Date: Feb 2007
Location: Essex, UK
Posts: 250
Thanks: 1
Thanked 23 Times in 22 Posts
Actinia is on a distinguished road
You could put the two images into one div (called say wrap), then center that using margin auto.
Code:
.newspost #wrap {
display:block;
border:0px;
text-align:center; /* keep IE6 happy */
width: 500px; /* sufficient to hold both images */
}
.newspost #wrap img{
margin-left:auto;
margin-right:auto;
}
John
Actinia is offline   Reply With Quote
Old 01-21-2008, 03:42 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
What's wrong in giving just text-align:center to the container of all these hyper linked imgs and then giving
Code:
a img {border:none}
?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-21-2008, 05:41 PM   PM User | #5
Apostropartheid
The Apostate


 
Apostropartheid's Avatar
 
Join Date: Oct 2007
Posts: 3,215
Thanks: 16
Thanked 265 Times in 263 Posts
Apostropartheid is on a distinguished road
Because that leaves the image inline, and that leaves extra space for descending letters =P
__________________
Blog | Twitter
Useful links: W3C HTML Validator | W3C CSS Validator | HTML 5 Guide
CF: HTML & CSS Resources/Tutorials Thread | HTML & CSS Posting Rules and Guidelines
Remember: no link, no code, no help!
Apostropartheid 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 10:57 AM.


Advertisement
Log in to turn off these ads.