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 793819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:12:54+00:00 2026-05-14T22:12:54+00:00

Ok, I am a complete beginner to this, in fact I am still building

  • 0

Ok, I am a complete beginner to this, in fact I am still building my first website. I am attempting to do this all by hand-coding without a CMS in order to try and learn as much possible as quickly as possible. If this post is in the wrong place I apologise, and a pointer to right place would be appreciated.

Here goes, I am trying to piece together a bit of jQuery that will automatically vertically align my thumbnails in my image gallery (they are all different sizes). They are within fixed size div’s and the function I am attempting looks something like this:

<script type="text/javascript">

$('#ul.photo).bind(function() {

var smartVert=$(this);

var phty=ob.("ul.photo img").height(); //get height  of photos

var phtdif=Math.floor(208 - phty); //subtract height of photo from div height

var phttop=Math.floor(phtdif / 2); //gets padding reqd.

$ob.("ul.photo").css({'padding-top' : phttop}) //sets padding to center thumbnail

});

smartVert();

</script>

Unsurprisingly this doesn’t work, if some kindly soul could take pity on a total noob, and point out where I am going wrong (probably in writing complete gibberish would be my first guess), it would be greatly appreciated – even if you could just point me in the direction of a tutorial regarding these things. I have looked and found one reference that said such a function was easy to create, but it did not elaborate.

  • 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-14T22:12:55+00:00Added an answer on May 14, 2026 at 10:12 pm

    made some code here for you

    for example:

    html

    <div id="yourdiv">
        <img height="200" width="100" src="x" />
        <img height="100" width="100" src="x" />
        <img height="150" width="100" src="x" />
        <img height="300" width="100" src="x" />
    </div>​
    

    css

    #yourdiv {
        height: 400px;
        background-color: black;
    }
    #yourdiv img {
        margin: 0 10px;
    }
    

    js

    $(document).ready(function() {
        var $yourdiv = $("#yourdiv");
        var divHeight = $yourdiv.height();
    
        $("img",$yourdiv).each(function() {
            var imgElement = $(this);
            var imgPadding = (Math.floor((divHeight-imgElement.height()) / 2));
            imgElement.css('margin-top',imgPadding+'px');
        });
    });​
    

    ​

    ​
    edit:

    for better aligning: set your images to block and float them left. then clearfix your div.

    edit 2:

    looping through an set of objects with a for-loop is faster than using .each

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

Sidebar

Related Questions

First off, I'm a complete beginner at C++. I'm coding something using an API,
I'm a (near complete) beginner, and this is my first foray into encryption -
I'm a complete beginner, and this is how I understand linking: Static linking copies
I am a complete beginner in asp.net, C#, etc... I saw this and this
I'm still a complete beginner in the field of web development and I'm trying
I'm a complete beginner with jQuery and I have this bit of script here
I am a complete beginner in Flash & Actionscript. My pet project is this:
I'm a complete beginner in php (and a first 'poster' here on SO) and
I'm a complete beginner in the tcl/tk world, but I've tried to research this
I'm a complete beginner trying to learn Java as my first language. When I'm

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.