/    Sign up×
Community /Pin to ProfileBookmark

vertically center an image in a "gallery"

Another question today. Woo!

Alright, so I have these images that maybe be different sizes. There’s going to be PHP, so no telling what the sizes will be. At max they will be 100×100, but they could be 95×100, 73×68, etc. I’ve got them centered horizontally, but not vertically. Check it out: [url]www.hookedonwinter.com/newdesign[/url]
here’s some relevant code:

CSS:

[code]
.thumbnail{
float:left;
width:106px;
height:106px;
margin: 15px 31px;
text-align:center;
}

.thumbnail img{
border:3px solid #122D5A;
/*this is probably where I need an auto margin or something, I just can’t figure it out…*/
}
[/code]

[code=html]
<div class=”thumbnail”>
<img src=”images/myteamplaceholder.png” alt=”MyTeam”>
</div>

<div class=”thumbnail”>
<img src=”images/placeholder.png” alt=”MyTeam”>
</div>

<div class=”thumbnail”>
<img src=”images/myteamplaceholder.png” alt=”MyTeam”>
</div>

<div class=”thumbnail”>
<img src=”images/myteamplaceholder.png” alt=”MyTeam”>
</div>
[/code]

the second image is smaller than the rest (75×75 rather than 100×100), and it is vertically aligned to the top. I want it in the middle. ideas? Thanks,

PJ

p.s. Graeme – thanks for your help on the text selecting problem. Worked great!

to post a comment
CSS

6 Comments(s)

Copy linkTweet thisAlerts:
@agrestikFeb 08.2007 — Hi HookedOnWinter,

Add the text in bold to the .thumbnail class

[CODE].thumbnail{
float:left;
width:106px;
height:106px;
margin: 15px 31px;
text-align:center;
[B]vertical-align:middle;[/B]
}[/CODE]
Copy linkTweet thisAlerts:
@HookedOnWinterauthorFeb 08.2007 — isn't that for inline objects? i'm using block objects here...

and it didn't work.. thanks though
Copy linkTweet thisAlerts:
@HookedOnWinterauthorFeb 11.2007 — bump, still can't figure it out..
Copy linkTweet thisAlerts:
@HookedOnWinterauthorFeb 16.2007 — bump. anyone?
Copy linkTweet thisAlerts:
@toicontienFeb 16.2007 — I ran into this same problem at Motortopia.com. My solution was fairly easy, which I'll adapt to your markup.
<i>
</i>.thumbnail {
float: left;
height: 100px;
position; relative;
width: 100px;
}

.thumbnail .thumbBox {
left: 0;
position: absolute;
text-align: center;
top: 50%;
width: 100px;
}

.thumbnail .thumbBox img {
vertical-align: bottom;
}

Now the HTML:
<i>
</i>&lt;div class="thumbnail"&gt;
&lt;div class="thumbBox" style="height: [B][image height][/B]px; margin-top: -[B][Half of this image's height][/B]px;"&gt;&lt;img ...&gt;&lt;/div&gt;
&lt;/div&gt;

The downside is it does require you to know the dimensions of each image, which you can get with a PHP function -- http://us2.php.net/manual/en/function.getimagesize.php
Copy linkTweet thisAlerts:
@HookedOnWinterauthorFeb 16.2007 — awesome, thank you! i'll play with this next week. Thanks!
×

Success!

Help @HookedOnWinter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...