DEV Community

HidetoshiYanagisawa
HidetoshiYanagisawa

Posted on

Elevate Your Site to the Next Level! Master Landscape & Portrait Mode with CSS Media Queries

Table of Contents

  1. Introduction
  2. Landscape Mode Support
  3. Portrait Mode Support
  4. Combining Them
  5. Conclusion

1. Introduction

Responsive design is an essential skill in modern web development. In this article, we'll explore how to utilize CSS media queries to cater to both landscape and portrait modes on various devices.

2. Landscape Mode Support

Designing for landscape mode (horizontal orientation) can be implemented as follows:

Sample Code

/* Landscape mode styling */
@media only screen and (orientation: landscape) {
  body {
    background-color: lightblue;
  }
  /* Additional styles for landscape mode here */
}
Enter fullscreen mode Exit fullscreen mode

3. Portrait Mode Support

For portrait mode (vertical orientation), the implementation would look like this:

Sample Code

/* Portrait mode styling */
@media only screen and (orientation: portrait) {
  body {
    background-color: lightpink;
  }
  /* Additional styles for portrait mode here */
}
Enter fullscreen mode Exit fullscreen mode

4. Combining Them

Landscape and portrait modes can be combined, allowing you to target specific device sizes:

Sample Code

@media only screen and (orientation: portrait) and (min-width: 400px) {
  /* Styles for portrait mode with a width of 400px or more */
}
Enter fullscreen mode Exit fullscreen mode

5. Conclusion

Using CSS media queries for landscape and portrait mode support is a powerful tool for responsive design. With this knowledge, you can implement beautiful designs that cater to various devices and screen sizes.

Don't forget to like and follow!

Top comments (0)