max-height in conjunction with width

I've got an app that I've developed that allows users to take pictures/upload it to a database of images.  Obviously they can take pictures that are either landscape or portrait - and I'm not quite sure how to properly handle the CSS with respect to that.

In the event that the picture is landscape - I want the width to be 100%.  So, I set the CSS to "width:100%;"

If the picture is portrait, however, there's decent odds that having the width be 100% will result in an image that forces the user to scroll down on the device...(in other words - 100% width causes the image to be too large to be encapsulated on the screen along with the other elements) - so I'd *like* the max-height to be like 70% or so.

How would I go about accomplishing both?  I've tried various combinations of "max-height: 70%; max-width:100%;" etc...but that's not it.  :)  Is there another approach that would work?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You need to constrain your display box to a certain height width and then use

max-width: 100%;
max-height: 100%;

Sample code below - working sample here
The sample demonstrates how you can switch between landscape / portrait in the same box and keep the proportions of the image.
<!doctype html>
<link href="css/bootstrap.css" rel="stylesheet" />
<style type="text/css">
img {
  max-width: 100%;
  max-height: 100%;
.image-box {
  height: 500px;
<div class="container">
  <h4>Demonstration of Portrait / Landscape images</h4>
  <h5>Author: Julian Hansen, August 2015</h5>
  <p>Click the images below to switch them. Change the height of the image box by modifying the value in the input below</p>
  <p>Height <input type="text" id="theheight" value="500" /></p>
  <div class="image-box">
    <img src="images/portrait.jpg" />
  <div class="image-box" style="display: none">
    <img src="images/landscape.jpg" />

<script src=""></script>

<!-- Latest compiled and minified JavaScript -->
<script src="js/bootstrap.js"></script>
$(function() {
  $('#theheight').keyup(function() {
    var height = parseInt($(this).val());
    $('.image-box').css({height: height + 'px'});
  $('.image-box').click(function() {

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erzoolanderAuthor Commented:
Gracias -
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.