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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:00:29+00:00 2026-05-23T06:00:29+00:00

I need to create a clickable div with an image (of variable size, but

  • 0

I need to create a clickable div with an image (of variable size, but that is smaller than the div) centered both horizontally and vertically within the div.

I made the div clickable with

    #image-box a { display: block; height: 100%; width: 100%; }

but can’t seem to center the image vertically.

  • 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-23T06:00:30+00:00Added an answer on May 23, 2026 at 6:00 am

    Try this adjusting width and height of your a element as explained in the comments:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Centered Clickable Image</title>
        <style type="text/css" media="screen">
        #image-box {
                position:absolute; 
                top:0; bottom:0; left:0; right:0;
                margin:auto; 
                border: 1px solid #999;
                text-align: center;
                }
    
        #image-box a {display:block; position:absolute; 
                top:0; bottom:0; left:0; right:0;
                margin:auto; text-align: center;
                }
    
        /* insert the same width and height of your-nice-img.png */
        #image-box a {width:339px; height:472px; border: 2px solid red;}
    </style>
    </head>
    <body>    
        <div id="image-box">
            <a href="#">
                <img src="your-nice-image.png" alt="image to center"/>
            </a>
        </div>
    </body>
    </html>
    

    NOTES:
    Borders are needed only for visual debug, You can delete them at any time.

    The trick here is that you use an absolute positioned div (#image-box) with a fixed width and height.

    If you set the #image-box a top and bottom position to zero the rule margin:auto puts #image-box a element in a middle position (on the vertical axis) because it has a fixed height, .

    If you can or like to solve It using jQuery, try this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Centered Image</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    
        </head>
        <body>
            <div id="image-box">
                <a href="#">
                    <img src="canning.png" alt="image to center"/>
                </a>
            </div>
    
        <script type="text/javascript" charset="utf-8">
        $(document).ready(function(){
            $(window).resize(function(){
                $('#image-box a').css({
                    position:'absolute',
                    left: ($(window).width() - $('#image-box a img').outerWidth())/2,
                    top: ($(window).height() - $('#image-box a img').outerHeight())/2
                });
            });
                // first run
            $(window).resize();
        });
        </script>
        </body>
        </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a link for an ASP.NET page that has an image
I need create clone repository. but I do not know where can I get
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I need to have an image instead of clickable text and using MVC helpers.
I need to create a DHTML menu with the specified features, but I can't
I need some jQuery ajax help. I currently have a main content div that
I need to create an activity(view) that shows several lists, for example: (text)Fruits: (item)apple
I need to create a clickable 8 by 8 grid in pygame. Right now
I have over 30 clickable imagebutton views that I want to create programatically instead
I need create custom dialog and put JPanel into it. Is it possible?

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.