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

  • Home
  • SEARCH
  • 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 8456921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:40:24+00:00 2026-06-10T12:40:24+00:00

What I have is a standard form in HTML that allows the user to

  • 0

What I have is a standard form in HTML that allows the user to select a “Width” option and a “Height” option (each with values ranging from 1 to 10). When they send the form, it sends it to a PHP/HTML page where PHP grabs the “Width” and “Height” variables and assigns it to a width and height of a DIV.

But what I’m trying to do is just use the “Width” and “Height” variables to assign an aspect ratio to that DIV, and then have that DIV auto-resize to 100% of the container it is inside, but while keeping that same aspect ratio.

Example:
User selects a Width of 4 and a Height of 2, then sends the form. On the receiving PHP page, that DIV (the one receiving the width and height ratios) is inside a container that’s 1000px width and 600px height. So now, that DIV resizes to 1000px wide and 500px tall (that would be the aspect ratio of 4 to 2)

Any ideas, codes, scripts would be extremely helpful, thank you very much!

Aaron

  • 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-06-10T12:40:26+00:00Added an answer on June 10, 2026 at 12:40 pm

    Since percentage values of the padding-* properties are calculated with respect to the width of the generated box’s containing block, you could:

    • Add a dummy element with no content but with a percentage in a vertical padding (padding-top or padding-bottom), corresponding to the desired aspect ratio.
    • Use absolutely positioning to remove all contents from the normal flow of the element, in order to prevent them from increasing the height. Then, make it grow to fill the container.

    This idea is taken from http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio

    #container {
      position: relative;
      width: 50%;
    }
    #dummy {
      padding-top: 75%; /* 4:3 aspect ratio */
    }
    #element {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: silver;
    }
    <div id="container">
      <div id="dummy"></div>
      <div id="element">
        some text
      </div>
    </div>

    Note vertical margin could be used instead of vertical padding, but then there would be margin collapse. To prevent it, add

    #container {
      display: inline-block;
    }
    
    #container {
      display: inline-block;
      position: relative;
      width: 50%;
    }
    #dummy {
      margin-top: 75%; /* 4:3 aspect ratio */
    }
    #element {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: silver;
    }
    <div id="container">
      <div id="dummy"></div>
      <div id="element">
        some text
      </div>
    </div>

    Using ::before pseudo element, there’s no need to use a dummy element:

    #container:before {
      padding-top: 75%; /* 4:3 aspect ratio */
      content: ''; /* Enable the pseudo-element */
      display: block;    
    }
    
    #container {
      position: relative;
      width: 50%;
    }
    #container:before {
      padding-top: 75%; /* 4:3 aspect ratio */
      content: ''; /* Enable the pseudo-element */
      display: block;    
    }
    #element {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: silver;
    }
    <div id="container">
      <div id="element">
        some text
      </div>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standard html form that uses a background image. I would like
So I have some code here that takes user input from a standard web
I have a standard HTML form on a WordPress post that the visitor will
I have a form that has an option to enter dimensions for: Width &
I have a _form.html.erb partial that comes from the standard rails 3 template for
I have a pretty standard HTML form in which I collect user input. I
We currently have a form with the standard multi-select functionality of here are the
I have a snippet of HTML that is part of a form where there
I have a simple HTML form that uses uses ajax in part of the
I have an HTML form which consists of several fieldsets (each has identical fields).

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.