/    Sign up×
Community /Pin to ProfileBookmark

vertical-align for img

Is there anyway to vertically align an image and centre it in a <div>?

My div style is as follows;

div.img {position:absolute; top:110px; left:220px; width:350px; height:300px; background-color:#F0F0F0; align:center; vertical-align:middle}

I just want the image to be placed bang in the middle of the div.

Thanks,
John

to post a comment
CSS

5 Comments(s)

Copy linkTweet thisAlerts:
@VladdyDec 07.2003 — what kind of image is it?
Copy linkTweet thisAlerts:
@jasnjohnauthorDec 07.2003 — OK, the div is 350px across, and 300px high.

The image is just a 72dpi JPEG photo.

Some photos in the div will be landscape and others portrait, so I wanted them to always be smack in the middle of the div.

Cheers,

John
Copy linkTweet thisAlerts:
@VladdyDec 07.2003 — If your div size is fixed and the image size is known - use margins to position the image.

Also, if images would qualify as a presentational element rather than content, it would be easier to put them as element background.
Copy linkTweet thisAlerts:
@jasnjohnauthorDec 07.2003 — Thanks for the help.

I'll have to settle for use of margins as the images will change frequently as they're part of a gallery.

thanks again..
Copy linkTweet thisAlerts:
@ray326Dec 07.2003 — Put the image in as the background for the div and you can fiddle its alignment all you want.
×

Success!

Help @jasnjohn 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...