473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

center image in div

Hi,
I'm trying to center an image in a div, both horizontally and vertically.
(Each div holds a thumbnail image.)
Here's the HTML:

<div class="thumb">
<div>
<img src="tn_02-2022.jpg" />
</div>
<p>
<a href="../../dummy.htm">small</a> (480 x 320)<br />
<a href="../../dummy.htm">medium</a> (768 x 512)<br />
<a href="../../dummy.htm">large</a> (1536 x 1024) </p>
</p>
</div>

and this is the CSS:

div.thumb {
width: 125px;
height: 190px;
background-image: url(../../img/slide.png);
background-repeat: no-repeat;
padding: 10px;
float: left;
}

div.thumb div {
width: 120;
height: 120px;
margin: 0px auto 20px auto;
}

div.thumb p {
font-size: 9px;
line-height: 12px;
}

You can see the result here:
http://users.pandora.be/nenya/anor/i...is01/index.htm
The thumbs are not horizontally aligned, though I was hoping the "margin:
auto" would do the trick.

As for vertical alignment, Googling around I found solutions using tables
and even frames (for centering on a page).
Can I do it without tables? The CSS above doesn't contain anything for
centering vertically, 'coz I didn't know where to start :-(
I'd be really grateful if you guyz/galz can help me out.

Steven

Jul 20 '05 #1
3 29388
Els
steven wrote:
Hi,
I'm trying to center an image in a div, both horizontally and vertically.
(Each div holds a thumbnail image.)
Here's the HTML:

<div class="thumb">
<div>
<img src="tn_02-2022.jpg" />
</div>
<p>
<a href="../../dummy.htm">small</a> (480 x 320)<br />
<a href="../../dummy.htm">medium</a> (768 x 512)<br />
<a href="../../dummy.htm">large</a> (1536 x 1024) </p>
</p>
</div>

and this is the CSS:

div.thumb {
width: 125px;
height: 190px;
background-image: url(../../img/slide.png);
background-repeat: no-repeat;
padding: 10px;
float: left;
}

div.thumb div {
width: 120;
height: 120px;
margin: 0px auto 20px auto;
}

div.thumb p {
font-size: 9px;
line-height: 12px;
}

You can see the result here:
http://users.pandora.be/nenya/anor/i...is01/index.htm
The thumbs are not horizontally aligned, though I was hoping the "margin:
auto" would do the trick.

As for vertical alignment, Googling around I found solutions using tables
and even frames (for centering on a page).
Can I do it without tables? The CSS above doesn't contain anything for
centering vertically, 'coz I didn't know where to start :-(
I'd be really grateful if you guyz/galz can help me out.


There recently was a long thread about this stuff in
alt.html. First message of that thread: 23-2-2004 by Max
Quordlepleen, subject: Thumbnail gallery without tables?
message id: <wu**********@maxqnz.com>

Read that thread, and if you have questions afterwards, ask
again ;-)
--
Els

Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -

Jul 20 '05 #2
"steven" <st***********@pandora.be> wrote:
I'm trying to center an image in a div, both horizontally and vertically.
(Each div holds a thumbnail image.)
http://users.pandora.be/nenya/anor/i...is01/index.htm


Images are inline elements, so the horizontal centering is easy - just
add {text-align: center} to the div.

I don't trust any of the solutions around for vertical centering, I
think you should use two classes .horizontal and .vertical and set
different padding-top on them.

The 9px font is a bit fragile too, I get line-breaks because my
minimum font size is greater than 9px.

--
Karl Smith.
Jul 20 '05 #3
"Karl Smith" <go************@kjsmith.com> wrote in message
news:3d************************@posting.google.com ...
"steven" <st***********@pandora.be> wrote:
I'm trying to center an image in a div, both horizontally and vertically. (Each div holds a thumbnail image.)
http://users.pandora.be/nenya/anor/i...is01/index.htm
Images are inline elements, so the horizontal centering is easy - just
add {text-align: center} to the div.

I don't trust any of the solutions around for vertical centering, I
think you should use two classes .horizontal and .vertical and set
different padding-top on them.


No can do. The images don't have a fixed 2:3 aspect ratio, so the padding
could be different for each thumb. But that's OK; I can use inline styles. I
think I'll write a small code generator to create the pages from folder with
images.
The 9px font is a bit fragile too, I get line-breaks because my
minimum font size is greater than 9px.


Oops, my wrong. Of course you don't express font size in pixels. Thanks for
pointing out the error.

Steven
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tony Vasquez | last post by:
Can somoene give me an example of how to center a div, according to it's image size... I am using different images, and so I have to resize it in a functino according to the image's size. So I use...
13
by: Mike | last post by:
We are using: <!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" xml:lang="en"...
7
by: Sean | last post by:
Hi, I have a tab control containing few tab pages. On each tab pages, I put an image on the tab page's title bar (the area on top of a tab page, ie where tooltip will appear). If i put both...
4
by: x taol | last post by:
i want to display the image in center of form wherever the image located in the form using vba or and so on. *** Sent via Developersdex http://www.developersdex.com ***
1
by: judacris | last post by:
I've seen the threads here about molding 2 divs in a centered fashion. but I can't seem to solve this thing. my blogger blog is functioning well on my site for now, but the blog feed (left) and...
1
by: jobs | last post by:
I have a simple login page with roughly a 300px x 300px image behind the asp.net login control. I need the login control to land in the middle of the image. I want both the image and the login...
14
by: Summercool | last post by:
in http://www.0011.com/test_size3.html to center the logo "HTML 4.01 check" button at the bottom of the page, I used <div style="width: 10px; margin: 0px auto"> </div>
24
by: GloStix | last post by:
I'm trying to center this banner, it's in a div that has the same width so it's not exactly "centering" but it's screwed up, It works in safari but in Firefox it's messed up. I uploaded a Video to...
14
by: gaijinco | last post by:
I was a hobbist web coder for years but I had to sidestep for a while. Now I'm trying to return to it and I'm trying to clarify how am I supposed to do somethings with CSS v.s. HTML and I'm...
13
by: Stevo | last post by:
I've found that for IE6+, if you add the property text-align:center to a DIV, then *anything* inside it gets centered. That can be a table, an object/embed, another DIV, an image, or some text. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.