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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:15:57+00:00 2026-05-28T07:15:57+00:00

I have articles with display:table and an image wrapper inside with display:table-cell to achieve

  • 0

I have articles with display:table and an image wrapper inside with display:table-cell to achieve vertical and horizontal aligning of the images. The images are set to 80% width and height so when resizing the browserwindow the image should scale in ratio.

<article class="layer">
   <div class="wrap">
      <img src="whatever.jpg" alt="image"/>
   </div>
</article>

html, body, #content {
    margin: 0; padding: 0;
    height: 100%;
    width: 100%;
}

article.layer {
    position: relative;
    display: table;
    height: 100%;
    width: 100%;
}

article.layer img {
   max-width: 80%;
   max-height: 80%;
}

div.wrap {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

What I’m trying to do is keep the image always displayed fully. So I don’t want it to be cut off when resizing the browserwindow. This works fine right now when I resize the browserwindow horizontally, however it doesn’t when resizing it vertically.

Here is a sample: http://jsbin.com/ugumuj/10/edit#preview

Is there a way to achieve the same thing when resizing the browserwindow vertically as well?
I’d love to do it in a pure CSS way but I’d also use jQuery or Javascript to do so.

Any ideas? Thank you in advance.

  • 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-28T07:15:58+00:00Added an answer on May 28, 2026 at 7:15 am

    javascript:

    window.onresize = function(){
          $('article.layer img').css({
            maxHeight: $('article.layer').height() * 0.8,
            maxWidth: $('article.layer').width() * 0.8
          });
        };
    

    jQuery:

    $(window).resize(function(){
      $('article.layer img').css({
        maxHeight: $('article.layer').height() * 0.8,
        maxWidth: $('article.layer').width() * 0.8
      });
    });
    

    DEMO

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

Sidebar

Related Questions

Let's say you have a table containing articles and you want want to display
I have Table: ARTICLES ID | CONTENT --------------- 1 | the quick 2 |
I have a table 'articles' : id / uid / last_update / content. I
I have images being stored in folders related to articles on my PHP web
I have a table of Users: id, type, name and a table of Articles:
I have a table of users, some of which have articles associated with them,
I have a table called Tickets with id, name. and a table called Articles
I have this script to output everything from table called Articles. If I load
I have a table on my page and I want to display a message
I have a table: <table class=articles> <%= render :partial => 'articles/article' , :collection =>

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.