Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:31:07+00:00 2026-05-31T03:31:07+00:00

I have X amount of divs, all set to a specific height and width.

  • 0

I have X amount of divs, all set to a specific height and width. Within these is an image, all vary in size. I want to find the height of the image, divide it by 2 and set that as the margin top value so all images are in the centre if this makes sense? Ive tried making a fiddle only im unsure how to go about it…

http://jsfiddle.net/R8QUL/1/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:31:09+00:00Added an answer on May 31, 2026 at 3:31 am

    You could do something like this

    $(document).ready(function() {
    
        $('.box img').each(function() {
            var $this = $(this);
            var parentHeight = $this.parent().height();
            var thisHeight = $this.height();
            var topmargin = (parentHeight - thisHeight) / 2;
            $this.css("margin-top", topmargin);
        });
    })
    

    Fiddle here http://jsfiddle.net/R8QUL/6/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3 column, 2 row set of divs. I want to make
I have divs containing round brackets that I want to look for using the
I have a div with width:100px and height:100px (say) Inside that, there is just
I have a DIV container of 100% width holding x divs. The last child
I'm trying to set up a filter using jQuery. I'll have a certain amount
I have a random amount of DIVs (minimum 1, max of 10) <div id=container>
I have a dynamic amount of div's being returned from a query, all with
I have a form that contains an n amount divs each of wich contain
I have huge amount of txt files which contains 64x64 matrices consisting of integers.
I have an uncertain amount of nested ul and li tags like: <ul> <li>5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.