Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if the viewport width is greater than its height using a mediaquery

is there a way to perform this operation in css ? @media screen and (min-width < min-height)

I started writting a front-end library and I want "responsive" based on this condition.

like image 891
GwydionFR Avatar asked Jul 29 '15 07:07

GwydionFR


People also ask

How do I know my viewport width?

You can use the window. innerHeight property to get the viewport height, and the window. innerWidth to get its width. let viewportHeight = window.

Is height greater than width?

Because height is always vertical, either measurement, width or height, can be greater.

What is viewport width and height?

In an SVG document, the viewport is the visible area of the SVG image. You can set any height and width on an SVG, but the whole image might not be visible. The area that is visible is called the viewport. The size of the viewport can be defined using the width and height attributes of the <svg> element.

Does media query work with height?

Media queries can be used to check many things, such as: width and height of the viewport. width and height of the device.


1 Answers

Check for the orientation

@media all and (orientation: landscape) {
  body:after {
     content: "width is greater than height"
  }
}

@media all and (orientation: portrait) {
  body:after {
     content: "height is greater than width"
  }
}
like image 129
Fabrizio Calderan Avatar answered Nov 05 '22 02:11

Fabrizio Calderan