CSS

Responsive Web Design Using Media Query

Introduction

media query is a CSS functionality that allows the content of a Web page to adjust to the type of media that the page is being executed in, with a different screen like Desktop or mobile. Its introduce with CSS3, In simple words, we can say its an if-else block which execute when a written condition is true.

For example, If we wanna change page background color in tablet mode we can write,

@media only screen and (min-width: 768px) and (max-width: 999px) {
  body {
    background-color: red;
  }
}

Below is the screen size for different devices.

Big tablet view

@media only screen and (max-width: 1024px){
  //css
}

Tablet view

@media only screen and (min-width: 768px) and (max-width: 999px){
  //css
}

Mobile view

@media only screen and (max-width: 767px){
  //css
}

Desktops and laptops view

@media only screen  and (min-width : 1224px) {
 //css
}

Large screens view

@media only screen  and (min-width : 1824px) {
 //css
}

 iPads (portrait and landscape) view

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
 //css
}

iPhone 6, 7, 8 view

@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 2){
 //css
}
@media only screen and (min-device-width: 375px) and (max-device-height: 667px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 2){
 //css
}

iPhone X view

@media only screen and (min-device-width: 375px) and (max-device-height: 812px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
 //css
}

@media only screen and (min-device-width: 375px) and (max-device-height: 812px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
 //css
}

iPhone XS Max, XR view

@media only screen and (min-device-width: 414px) and (max-device-height: 896px) and (orientation : landscape) and (-webkit-device-pixel-ratio: 3){
 //css
}

@media only screen and (min-device-width: 414px) and (max-device-height: 896px) and (orientation : portrait) and (-webkit-device-pixel-ratio: 3){
 //css
}

 

There are some rules to create dynamic pages or websites.

  1. Always go with Mobile design first.
  2. Design for both Orientation Portrait / Landscape.
  3. Don’t use inline CSS for web pages.
Faisal Pathan

Faisal Pathan is a founder of TheCodeHubs, .NET Project Manager/Team Leader, and C# Corner MVP. He has extensive experience with designing and developing enterprise-scale applications. He has good skills in ASP.NET C#, ASP.NET Core, ASP.NET MVC, AngularJS, Angular, React, NodeJS, Amazon S3, Web API, EPPlus, Amazon MWS, eBay Integration, SQL, Entity Framework, JavaScript, eCommerce Integration like Walmart, Tanga, Newegg, Group-on Store, etc. and Windows services.

Share
Published by
Faisal Pathan

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago