i have a variable which is an image

$image = "<img src='$imagelocation' width='50px' height='50px'>";

i want it to be in the center of the td but it doesn't center vertically, it stays at the top, i did this

echo "<td valign='middle'><div class='rollover' align='center'>

<a href=\"imageview.php?id=$number\" onmouseover=\"ChgText($keyword)\">$image</a>  

</div>
</td>";

any ideas?

The "valign" property does not propagate from the parent to its children children!

Try testing that scenario of yours with static HTML first.
This way you can see where lies the problem.

But from where we are the problem is: the image nested in the div element.
The td valign is pointing to the div element not to the image, so the image will not be valigned because the hosting div is not required to do that with its own children too.

But in any case, the DIVs can't make your inline elements to render vertically aligned in the middle.

Also if you ask me, that DIV is not required and shouldn't be there at first place at all. Remove the div and asign its class to your image instead. >>Keep your HTML code clean.

all u need to do is center the image inside the div

Sorry for asking but
Are you sure you understand his question?

yes ansn i also understnad the first answer how it doesnt align the children

he needs to vertically align in the middle,
as I already mentioned with his actual code structure and his existing styles it can be fixed by simply removing the DIV wrapping his Image in TD elements, nothing else.
But, new comers never bother to come back and tell if some advice helped solve their problem or god forbid mark the thread solved.

no he probably has something else in the divs. just td middle align will center the div in side the table td but then u have to go ahead and also center the stuff inside tthe div. simple. then its centered.

Sorry, but css: vertical-align has no effect on divs, -therefore ...

im sorry did i forget to mention the div should be the size as the image in height? then its vertically centered hon

:') no not even then lady skunk, not even then. :'D

yes i have done it. u verticle center the td. then u add the div and center it in the td. then i make sure that the div is the height of the image inside it and then u make the td the height of the page. ive done it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.