Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout using vh does not scale with zoom

I've tried to create a login form using ONLY vh sizes. Doing this, in the hopes that the form, in all, would scale accordingly to the viewport.

It doesn't! For some reason zooming in, creates a blank space that keeps getting bigger the more you zoom, between the input fields and the text below.

http://jsfiddle.net/TnY3L/

The fiddle isn't very well made, just copied it from my project. But you can see what's wrong - and that's what counts.

Anyone have any idea as to how I were to go about fixing this?

<span id="loginform">
    <input type="text" name="login" class="LFORM" placeholder="USERNAME" />
    <input type="password" name="password" class="LFORM" placeholder="PASSWORD" />
    <button id="LB" type="button" style="font-size: 1.4vh;">OK!</button><br />
    <a href="" id="CALINK" style="font-size:1.4vh;">Create account</a>
    <a href="" id="FLLINK" style="font-size:1.4vh;">Forgot login?</a>
</span>

::-webkit-input-placeholder {
     font-size: 1.4vh;
}
#loginform {
     float: right;
     position: relative;
     top: 50%;
     transform: translateY(-50%);
     right: 1.5vh;
}
#CALINK {
     float:left;
     font-family:my_fat_font;
}
#FLLINK {
     float:right;
     font-family:my_fat_font;
}
#LB {
     border-radius: 0.4vh;
     font-family: my_fat_font;
     color: #ffffff;
     background: #ff9f2d;
     padding: 0.2vh 0.8vh 0.2vh 0.8vh;
     text-decoration: none;
     border: none;
     height: 2vh;
     margin-left: .5vh;
     margin-right: 0px;
     border: 0;
}
#LB:hover {
     background: #3e4188;
     text-decoration: none;
} 
.LFORM {
     width: 10vh;
     height: 1.8vh;
     border-radius: .3vh;
     border: none;
     padding-left: .6vh;
}
[placeholder]:focus::-webkit-input-placeholder {
     color: transparent;
}
#loginform a:hover {
     color: #ff9f2d;
     text-decoration:underline;  
}
#loginform a {
     color: #ff9f2d;
     text-decoration: none;
}
like image 374
Rasmus Hjorth Lüdeking Avatar asked Mar 04 '15 19:03

Rasmus Hjorth Lüdeking


People also ask

How do I stop a CSS layout from distorting when zooming in out?

To fix the problem with zooming in, try adding the min-width attribute to your outer countainer ( #container or #navbar ?). Setting min-width prevents the webpage from trying to shrink down beyond the specified width (i.e. 300px).

Does vh scale?

The vh and vh units are a measurement relative to the viewport size. 1vh is 1% of the current viewport height, so 100vh is always 100% height. No matter how much you zoom in and out, the viewport is still the same size. When you zoom in, you scale up the entire document (but not the viewport).

Can I use VH for width?

Moving to relative units to express length and using vh and vw style settings lets you control the widths and heights of elements no matter the viewport size. You can also use percentage-based units, but keep in mind that they're based on the parent element, while vh and vw style units are based on the viewport.

How do I zoom the same element size?

That is, using control-plus to increase text size and control-minus to reduce it.


1 Answers

The vh and vh units are a measurement relative to the viewport size. 1vh is 1% of the current viewport height, so 100vh is always 100% height. No matter how much you zoom in and out, the viewport is still the same size.

When you zoom in, you scale up the entire document (but not the viewport). It's logical that the space between elements increases as you zoom in the page, if that space is not defined in viewport units as well. Because the other elements don't increase it takes the document out of proportions.

If you want to create elements that scale as you zoom in, try using the rem unit. This is relative to the body's font size, so as you zoom the page in every value expressed in rem will scale accordingly.

like image 57
Stephan Muller Avatar answered Sep 20 '22 15:09

Stephan Muller