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

The Archive Base Latest Questions

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

I have simply no idea how to do so or if this is even

  • 0

I have simply no idea how to do so or if this is even possible with pure css?

This is my codebase …

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

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

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

So I have articles with a class layer and they are set to display:table because I want them to be as high and wide as the current viewport.

Each of those articles has one <img> inside with different sizes.

I’m trying to create a kind of responsive webdesign!

The <img>s inside of the articles should be centered within its parent article and have a margin of like 30px. When resizing the browser-window the image should be scaled as well.

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

First off: How can I center the image inside of the display:table element? It should be centered vertically and horizontally.

Do I have to assign a width and height of the image or is it possible to kind of set it to 100% width within the browserwindow and the extra 30px margin.

I guess I probably need a lot of javascript to do so, right?

Regards, matt

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

    The key to keeping the aspect ratio is to use max-width and max-height instead of width and height:

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

    For the centering, you can use an additional wrapper div, which is placed around the <img> element:

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

    However, adding the 30px margin is not that easy. The percent relations apply to the screen size, so simply adding a margin will make it overflow the screen. The easiest way might be to add a full-screen div with position: absolute, which would act as a new reference for the percent measurements.

    The complete code (without 30px margin) is here:
    http://jsbin.com/ugumuj/10/edit

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

Sidebar

Related Questions

I have no idea if this is even possible, but I thought I would
Not sure if this is even possible, but the basic idea of the code
First of all, excuse my poor topic title. I simply have no idea how
Very simply put: I have a class that consists mostly of static public members,
Simple idea: I have two images that I want to merge, one is 500x500
The basic idea of a masterpage is simple -- you have a block of
I have an idea for a simple application which will monitor a group of
a possibly simple problem, but weird why I have no idea how to do
In WPF 3.5 (with SP1), I have simply StackPanel that I would like to
I have a @variabletable simply defined as EOMDate(datetime), DandA(float), Coupon(float), EarnedIncome(float) 04/30/2008, 20187.5,17812.5,NULL 05/31/2008,

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.