Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS width = widest edge = landscape = vw, height = narrowest edge = portrait = vh

mdavid

Coder
Hi, I need clarification.
I thought vw and vh units where good for responsive design, but I'm confused how they apply in landscape and portrait views.
Am I correct in assuming that VW units always apply to the widest side, and VH units always apply to the narrower side?

Thanks
 
100vw = 100% of viewport width not screen. The vw changes when scrollbars are added. You can use 100% for width or, as W3C tells us, use overflow:auto;. I code with vw, but will change it to 100% if I run into problems.
 
Thanks OldMan,
What I wanted to know is if the widest viewport width is always always refered to as width, landscape and measured in vw units?
The narrower viewport width always as height, portrait, and measured in vh units

Thanks
 
I'm not sure what you mean, but width is from left to right (or right to left), and height is from top to bottom (or bottom to top).
 
So the viewport width changes depending on landscape or portrait view. How does that make vh and vw good units to use for responsive design?
That's exactly what a responsive design is supposed to do - change with the screen size.

If, let's say, you have a square, and you want it to take the full height of the screen and half the width, you would put width: 50vw; and height: 100vh; in your CSS
 
Hi John, thanks for this.
Really sorry to appear dumb - but there's something I'm not getting.
Say I have a viewport 700px X 300px, then in your example:
portrait view - height: 100vh; = 700px (1vh = 7px)
landscape view - height:100vh; = 300px (1vh = 3px)

Is that correct?
 

Latest posts

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom