Viewport: how to resize to fit vertical space?

Hi there everyone!

I’m trying to utilize the viewport CSS element to shrink a div to fit the viewable space. From what I’ve read, the magic command is:

max-height: 100vh;

but when I add that to my css, it doesn’t resize the container that it was applied to (“site-container” in the style)

Here’s the page in question:

I’m sure I’m just misunderstanding how to apply this element. Could someone set me straight on how to size site-container to vertically fit the viewport?

It is setting the height, but the content within the div is too large for it to work (add an overflow:scroll to see what I mean)

The problem is the images are hard coded heights and there just isn’t enough space available… For it to work, you’re going to need to revisit how you’re presenting your images (and making your logo responsive would help as well)

For example, you could add height: 20vh; min-height: 127px; max-height:254px; to your logo class and your logo is now responsive

Your images is are a bit trickier since you’re filling space full width there, so play with those to find where you want them to go.

Thanks for the help, Dave.

I’m misunderstanding what I used for the body images, I think. When I was writing it, I thought:

style="width: 100%; max-height:537px; height: auto;"

was telling the height of the image to remain in proper ratio to the width and that I wasn’t forcing a certain height for any of them. Am I understanding that incorrectly? Is it the max-height that is coming into play?

Actually, it’s the width of your photos and your logo that’s causing you the issues. You’ve set the width to 100% of the available size, and to set the height accordingly. Unfortunately for you, that means your height is almost always going to hit the max height. Anything over 1200px wide (which is almost nothing nowadays), and your images are all 537px tall. So you’ve got the 537px for your 2x pictures, 253px for your ring image and 254px for your logo (minimum - that grows as your viewport widens), 22px for your menu, and you’re at 1000 already before you even add in margins and padding.


The only way you can do this and keep aspect ratios intact is to use background images (at present).

As you are using empty alt attributes on images then effectively you have no content so background images would suffice.

This is a rough mock up of how the effect can be achieved.

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Document</title>
*, *:before, *:after {
	box-sizing:border-box;  /* ie8+ */
.header,.footer{height:1px}/* collapse to content height*/

.header h1{margin:0 auto;width:50%;}
.footer img{width:100%;height:auto;}

.footer .tc{
	background:url( no-repeat 50% 50%;
	border-bottom:5px solid #fff;

	border-bottom:10px solid #fff;
	background:url( no-repeat 50% 50%;
	border-left:10px solid #fff;
	border-bottom:10px solid #fff;
	background:url( no-repeat 50% 50%;

.main img{width:auto;height:100%}

/*  */
.menu {
    padding: 10px;
	margin:0 0 10px;
    background: #333;
    color: #FFF;
    font-weight: bold;
    overflow: hidden;
	display: flex;
    justify-content: space-between;
    text-align: center;
.menu a {
    padding: 0 10px;

@media screen and (max-width:600px){
	.menu a{display:none}


<div class="wrap table">
  <div class="header tr">
    <h1><a href="#"><img class="logo" src="" alt="After 5 events"></a></h1>
    <nav class="menu"> <a href="#">ABOUT</a> <a href="#">PACKAGES</a> <a href="#">LOVE NOTES</a> <a href="#">LOOKBOOK</a> <a href="#">CONTACT</a> </nav>
  <div class="main tr">
    <div class="table">
      <div class="leftimg">&nbsp;</div>
      <div class="rightimg">&nbsp;</div>
  <div class="footer tr"><div class="tc">&nbsp;</div></div>

It has to be that structure and you can’t add divs outside .wrap.

I haven’t done the media queries but you should get the picture with the above. Just take the code and view it in your browsers to see how it looks as the urls are absolute so it will work as long as you are online.

Once you see how it works you may indeed think that the version you have already shows the images off to better effect but of course that’s a design choice.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.