Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2424

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T05:16:08+00:00 2024-11-26T05:16:08+00:00

A Ridiculously Simple Way For Creating Responsive Web Apps

  • 61k

I remember my first encounter with responsive design. Before any investigation, it seemed incredibly complex.

The same app runs and behaves differently based on so many types of user devices?

I have to cover all the screen sizes, from ultra-wide monitors, over laptop and tablet devices, all the way to the smartphones?

Mate, that must be a nightmare.

But honestly, it isn't. 

Responsive design is nothing more than a bunch of if statements.

Let's dive deeper into the topic.


Two Types of Design

Depending on what you create, you have two choices:

  1. Mobile-First Design
  2. Desktop-First Design

Mobile-First Design means that you first design and create software for mobile devices, and then extend it to desktop devices.

It assures that your core functionality will be available on a mobile device.

It's easy to add more functionality on the bigger screen, but it's hard to strip away functionality and keeping the core while going to a smaller screen.


According to this research, 68.9% of websites visit came from mobile devices.

If you're creating a consumer app, Mobile-First Design is likely to be your choice.

Complex B2B solutions require Desktop-First Design, and sometimes don't even have a fully functioning mobile solution - they're just too complex.

That's why I'll focus on Mobile-First Design in this article.


The Design

We'll keep this simple. Let's say that you have a number of items you want to display on your feed. It will look something like this:

Mobile design

Mobile design

We have two components here:

  1. Parent component, container 
  2. Child components, items 

If we ignore the CSS code for everything except the layout, it will look something like this:

<!DOCTYPE html> <html lang="en">   <head>     <meta name="viewport" content="width=device-width, initial-scale=1.0">   </head>   <body>     <div class="container">       <div class="item">Item 1</div>       <div class="item">Item 2</div>       <div class="item">Item 3</div>     </div>   </body>    <style>     .container {       display: grid;       grid-template-columns: 1fr;       align-content: flex-start;       gap: 16px;       padding: 16px;     }      .item {       padding: 88px 16px;     }   </style> </html> 
Enter fullscreen mode Exit fullscreen mode

Can you see the meta tag, <meta name="viewport" content="width=device-width, initial-scale=1.0">?

It's incredibly important and there's no responsive design without it. Without it, your browser won't know the initial zoom and it will look really bad on mobile devices.


Doing the Magic to Make the Desktop Work

Just joking, this is no complex magic. As I've said, just a bunch of if statements!

We're trying to spread the items, keeping 3 of them in each row:

Desktop design

Desktop design

The code looks like this:

<!DOCTYPE html> <html lang="en">   <head>     <meta name="viewport" content="width=device-width, initial-scale=1.0">   </head>   <body>     <div class="container">       <div class="item">Item 1</div>       <div class="item">Item 2</div>       <div class="item">Item 3</div>     </div>   </body>    <style>     .container {       display: grid;       grid-template-columns: 1fr;       align-content: flex-start;       gap: 16px;       padding: 16px;     }      .item {       padding: 88px 16px;     }      @media (min-width: 992px) {       .container {         grid-template-columns: 1fr 1fr 1fr;       }     }   </style> </html> 
Enter fullscreen mode Exit fullscreen mode

We're finally here, introducing @media queries. 

Let's read this in a simple, already familiar way:

if (screen width is bigger or equal than 992px) {     apply styles in the same way as before } 
Enter fullscreen mode Exit fullscreen mode

And that's it! Nothing more than this! The styles here will affect only screens wider than 992px.


How About Tablet?

You can combine media queries with logical operators. 

Yep, you can do something like:

@media (min-width: 768px) and (max-width: 991px) {     // styles } 
Enter fullscreen mode Exit fullscreen mode

And those styles will affect everything in range from 768px to 991px.

Remember, this is nothing more than an if statement.


How to Cover All Devices

Media queries are much more than just min-width and max-width.

You can check stuff like orientation, aspect-ratio, and much more.

You can use logical operators like or, not, and all the others.

But to be honest, what you've read in this article is enough for an amazing and simple start.

You probably won't need most of the other queries anyway. Maybe in some rare scenarios. By then, your knowledge about queries will be so powerful that complex queries will be a joke!


Loving my work? Feel free to buy me a croissant. It's an incredible boost to my motivation.

Check out the bottom of the originally published article on Medium for the best course around responsive web.

cssfrontendhtmlwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.