473,511 Members | 15,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

centering images within a <div>

71 New Member
I'm using two divs to create a shadowed-box type effect. Within the top div I want to put an image. I can get the image to center right to left, but not top to bottom. I'm making a series of boxes, and the images in them aren't all the same size. So I've sized the boxes to mach the largest of them, and I want to center them, so those that are smaller will be in the middle of the first div.

Here's the code on the page:

<table border="0" cellpadding="23" cellspacing="0" bordercolor="#FF33FF" width="900" bgcolor="#c4c4c4">
<tr>
<td align="center" valign="middle">
<div id="shadowdiv" align="center">
<div id="imagediv" align="center" style="height: 187px;"><img src="/images/manna2.gif" alt="" /></div>
</div>
</td>
<td align="center" valign="middle">
<div id="shadowdiv" align="center">
<div id="imagediv" style="height: 187px;"><img src="/images/fit2.gif" alt="" /></div>
</div>
</td>
</tr>

<tr>
<td align="center" valign="middle">
<div id="shadowdiv" align="center" >
<div id="imagediv" style="height: 187px;"><img src="/images/3dlogo2.gif" alt="" /></div>
</div>
</td>
<td align="center" valign="middle">
<div id="shadowdiv" align="center">
<div id="imagediv" style="height: 187px;" align="center"><img src="/images/smallgroups2.gif" alt="" /></div>
</div>
</td>
</tr>

<tr>
<td align="center" valign="middle">
<div id="shadowdiv">
<div id="imagediv" style="height: 386px;"><img src="/images/christmasshow2.gif" alt="" /></div>
</div>
</td>
<td align="center" valign="middle">
<div id="shadowdiv">
<div id="imagediv" style="height: 386px;"><img src="/images/servicetimes2.gif" alt="" /></div>
</div>
</td>
</tr>
</table>


Here's the css regarding the two divs:

#shadowdiv {
width: 360px;
padding: 5px;
filter: shadow(color:red, strength:6, direction:135);
vertical-align: middle;
text-align: center;
}

#imagediv {
width: 350px;
text-align: center;
padding: 0px;
background-image: url(/images/marb009.jpg);
border: 1px solid black;
font-size: 12px;
vertical-align: center;
}

As I play with the text-align property it moves the image horizontally, the vertical-align property seems to have no effect on the image placement though. I'm making the page in IE.

I'm thinking if nothing else I could try putting a table in the div, then put the image in the table, and center it that way... but if there's a way to do it with just the divs, that'd be preferable.
Nov 3 '06 #1
3 7839
rsteph
71 New Member
Any thoughts on this?
Nov 3 '06 #2
Thevercad
26 New Member
As far as i know, you cannot align elements inside a div, vertically. You can go for the option of padding-top and padding-bottom. But if your images are going to be of different height, even that might be a problem.

Inside the div, if you put a table, and the image inside it, then it could solve your problem. But the question then arises, why use the div at all.
Nov 6 '06 #3
rsteph
71 New Member
The Divs were used to create the shadowed effect. A div behind a div kind of thing. Though now they are thinking instead of a shadowed effect, that want a button effect, So I'll probably just go with a table with thicker borders... work with the various border color options to make it appear as a raised button.


As far as i know, you cannot align elements inside a div, vertically. You can go for the option of padding-top and padding-bottom. But if your images are going to be of different height, even that might be a problem.

Inside the div, if you put a table, and the image inside it, then it could solve your problem. But the question then arises, why use the div at all.
Nov 6 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4618
by: CMAR | last post by:
To center my <div>, I am currently using something like <div id="navcontainer" align="center"> This centers fine, but is deprecated code. I have seen these two solutions recommended. 1) ...
3
4189
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
7
3607
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
2
2943
by: Nikolai Onken | last post by:
Hey, I am trying to learn the exact behavior of CSS and was just placing a couple of <div>'s after each other. Each of the <divhas a <pwithin and some text within the <p> Now when I add a...
5
13405
by: Agix | last post by:
Hi there, Please check out : http://clarifysolutions.co.uk/certenroll/ The source is included below. This page is a test, so I can play about with paddings, margins and layouts using divs as...
8
609
by: CJM | last post by:
I've inserted a new banner in an existing page and I want the banner image to be centered (horizontally) within its container. I'm not bothered whether the accompanying line of text is restricted...
4
5267
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be...
8
10016
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF...
6
19248
goatboy
by: goatboy | last post by:
So I am hosting a site from my home server, and I would like the main page to be an area for updates about the site. I am providing these updates in a blog-style format, using this code: ...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.