align 4 images center

Hi All

I have a div that has 4 images in it, the div is set to 100% width and i need to know how to get all of the images to align to the center of there quater of the main div

like this

<<--------------------------divMain------------------------->>
|                    |                    |                    |                    |
        img1              img2              img3              img4      



<div id="main" style="wigth=100%">

<img id="img1" src="path"/>
<img id="img2" src="path"/>
<img id="img3" src="path"/>
<img id="img4" src="path"/>

</div>
LVL 1
willa666Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LZ1Commented:
What do you mean quarter the main div?  Like 4 equal sections?
To just center the images you could do:
<div id="main" style="width: 100%; text-align:center;">
 
0
numberkruncherCommented:
Try the following:

Let me know how you get on!
<!-- Note:
   "width" was spelt wrong, but isn't usually needed in a DIV.
   "text-align" controls this type of alignment.
-->
<div id="main" style="text-align: center">

<img id="img1" src="path"/>
<img id="img2" src="path"/>
<img id="img3" src="path"/>
<img id="img4" src="path"/>

</div>

Open in new window

0
willa666Author Commented:
Hi All

lets say the width is 800px wide and each image is 100 px wide. this means that each image would need 50px on the left and right of each image.

now i know i could just specifiy the px on left and rigth but i wanted a auto way of doing it in as the wide of the main div changes.

Ww
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

LZ1Commented:
Like this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style> 
#main {
		margin:0px auto; 
		width: 800px; 
		border: 1px solid #999;
		height:100px;
		text-align:center;
	}
#img1, #img2, #img3, #img4 {
	width: 100px;
	padding-right: 20%;
}

</style>
</head>

<body>
<div id="main"> 
 
<img id="img1" src="path"/> 
<img id="img2" src="path"/> 
<img id="img3" src="path"/> 
<img id="img4" src="path"/> 
 
</div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
willa666Author Commented:
hi LZ1

is there a way of using auto rather then a defined value?
0
Dave BaldwinFixer of ProblemsCommented:
You could use a table inside the DIV with 4 cells set to:
<td align="center" width="25%"><img id="img1" src="path"/></td>
Old fashioned "Deprecated" but it works and it's easy.

Or you can use the code below.  Note the <br clear="all" /> after the div containing the images.  That seems to be necessary when the height isn't defined.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Image DIVs</title>
</head>
<body>


<div style="width: 800px; text-align: center; background-color: #eeeeee; margin-left: auto;margin-right: auto;">
<div style="float: left; text-align: center; width:25%; background-color: #ddddff;"><img id="img1" src="warning.gif"/></div>
<div style="float: left; text-align: center; width:25%; background-color: #ddffdd;"><img id="img2" src="warning.gif"/></div>
<div style="float: left; text-align: center; width:25%; background-color: #ffdddd;"><img id="img3" src="warning.gif"/></div>
<div style="float: left; text-align: center; width:25%; background-color: #dddddd;"><img id="img4" src="warning.gif"/></div>
</div>
<br clear="all" />
<div>Next line....</div>

</body>
</html>

Open in new window

0
LZ1Commented:
Auto for which value?  You can use auto, but sometimes it doesn't pan out the way you want it to.  
The table method is an alternative, however I wouldn't suggest it. It's going to be unpredictable across browsers and actually the CSS solutions would probably give you a lot more flexibility.
0
LZ1Commented:
Any updates?
0
LZ1Commented:
Any updates?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.