Configuring Media Query for iPad Air and iPad Pro

I'm facing a challenge setting up media queries for different iPad devices in my Next.js code. I have three cards (or divs) arranged in a row, utilizing the React-Bootstrap grid system for layout. While the cards default to full width within the grid system, I aim to restrict their width to specific pixels using CSS media queries. Here's what I have so far:

CSS:

/* Default styles for all devices */
.post-card-main-wrapper {
  position: relative;
  margin: 0 auto;
  width: 320px;
}

/* iPad Pro styles */
@media only screen and (min-width: 1024px) {
  .post-card-main-wrapper {
    width: 400px;
  }
}

/* iPad Air styles */
@media only screen and (min-width: 768px) and (max-width: 1023px) {
  .post-card-main-wrapper {
    width: 220px;
    height: 350px;
  }
}

/* Styles for smaller screens (e.g., iPhone) */
@media only screen and (max-width: 767px) {
  .post-card-main-wrapper {
    width: 300px;
    height: 450px;
  }
}

/* Styles for the smallest screens (e.g., iPhone SE) */
@media only screen and (max-width: 479px) {
  .post-card-main-wrapper {
    width: 300px;
    height: 450px;
    margin: 0;
  }
}

HTML:

...

Adding desktop view (using iPad Air for development) screenshot:

https://i.sstatic.net/dii3y.jpg

My challenge lies in maintaining consistent card width across devices. The width settings for iPad Air work well, but when I set up a separate query for iPad Pro, it seems to override the iPad Air styles, resulting in cramped card spacing. I'm struggling to find a solution that caters to various devices while adhering to responsive CSS best practices. Any guidance on setting up media queries for multiple devices in Google Chrome's dimensions and general CSS responsiveness rules would be highly appreciated.

Answer №1

Have you considered using

.post-card-main-wrapper { max-width:100%; }
?
With your approval, rather than altering the HTML, I simply eliminated your media queries in the CSS, streamlining the code to just two lines:

.post-card-main-wrapper {
  margin: 0 auto 30px;
  width: min(400px, 100%);
  /* width: 400px; */
  /* max-width: 100%; */
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9af8f5f5eee9eee8fbeadaafb4aab4a8">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"  crossorigin="anonymous">
  
<div class="container-fluid">
  <div class="row">
      <div class="col-12">
          <div class="ant-divider css-dev-only-do-not-override-1i536d8 ant-divider-horizontal ant-divider-with-text ant-divider-with-text-left ant-divider-no-default-orientation-margin-left" role="separator">
              <span class="ant-divider-inner-text" style="margin-left:100px">
                  <h2>Featured Posts</h2>
              </span>
          </div>
      </div>
  </div>
  <div class="justify-content-center row">
      <div class="col-xl-4 col-md-4">
          <div class="post-card-main-wrapper">
              <div class="post-card-img-wrapper"><img src="https://yuma.sharkthemes.com/blog-one/wp-content/uploads/sites/3/2022/01/hand-person-girl-woman-hair-photography-78292-pxhere.com_-600x800.jpg" height="100%" width="100%"></div>
              <div class="post-card-content-wrapper" style="background:white">
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">PHOTOGRAPHY, PORTRAIT</span>
                  <h3>Some Article Title Here</h3>
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">December 2, 2022</span>
                  <div class="ant-typography ant-typography-ellipsis ant-typography-ellipsis-multiple-line css-dev-only-do-not-override-1i536d8" style="font-size: 16px; margin-top: 1em; -webkit-line-clamp: 4;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.</div>
              </div>
          </div>
      </div>
      <div class="col-xl-4 col-md-4">
          <div class="post-card-main-wrapper">
              <div class="post-card-img-wrapper"><img src="https://yuma.sharkthemes.com/blog-one/wp-content/uploads/sites/3/2022/01/hand-person-girl-woman-hair-photography-78292-pxhere.com_-600x800.jpg" height="100%" width="100%"></div>
              <div class="post-card-content-wrapper" style="background:white">
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">PHOTOGRAPHY, PORTRAIT</span>
                  <h3>Some Article Title Here</h3>
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">December 2, 2022</span>
                  <div class="ant-typography ant-typography-ellipsis ant-typography-ellipsis-multiple-line css-dev-only-do-not-override-1i536d8" style="font-size: 16px; margin-top: 1em; -webkit-line-clamp: 4;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.</div>
              </div>
          </div>
      </div>
      <div class="col-xl-4 col-md-4">
          <div class="post-card-main-wrapper">
              <div class="post-card-img-wrapper"><img src="https://yuma.sharkthemes.com/blog-one/wp-content/uploads/sites/3/2022/01/hand-person-girl-woman-hair-photography-78292-pxhere.com_-600x800.jpg" height="100%" width="100%"></div>
              <div class="post-card-content-wrapper" style="background:white">
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">PHOTOGRAPHY, PORTRAIT</span>
                  <h3>Some Article Title Here</h3>
                  <span class="ant-typography css-dev-only-do-not-override-1i536d8">December 2, 2022</span>
                  <div class="ant-typography ant-typography-ellipsis ant-typography-ellipsis-multiple-line css-dev-only-do-not-override-1i536d8" style="font-size: 16px; margin-top: 1em; -webkit-line-clamp: 4;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.</div>
              </div>
          </div>
      </div>
  </div>
</div>

Answer №2

I wanted to provide you with the basic concept so that you can implement the code on your own.

Take a look at the css styling for the container-fluid class. If the display property of container-fluid is set to flex, then three columns will be displayed regardless of the screen size.

Alternatively, if the display property of col-xl-4.col-md-4 class is set to inline-block, with a width specified between 25% to 33%, and each column has float:left applied to it, this layout will be achieved. This method was commonly used before media screen queries became popular.

It's important not to specify a fixed height so that the height adjusts automatically. To maintain consistent image sizes across different screen widths, specify a min-width to accommodate smaller devices. Additionally, set an actual width ranging from 80% to 100% based on your design needs.

@media only screen and (/* min width */) and (/* max-width */){

  container-fluid{display:block
  }
.col-xl-4.col-md-4{
   display : block !important;
   float:none !important;
   min-width: 300px; /*Adjust as needed */
   width : 90%; /*Adjust as needed */
   height:auto;
   margin : 0 auto;
   }
}
 

Answer №3

If you're looking to improve your website layout, I suggest transitioning to flexbox (sometimes referred to as flex). While Bootstrap now incorporates flexbox functionality, learning how to utilize it independently can be beneficial. Check out this helpful tutorial for mastering flexbox and maximizing Bootstrap's flex capabilities:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Boxes maintain their height consistency even after a page refresh

I Implemented This Script to Ensure Same Height for Boxes <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js"> $(document).ready(function(){ var highestBox = 0; $('.box').each(function(){ ...

What is the best way to rearrange the order of navbar items when working with two nav bars and a single toggle in bootstrap 4?

I am looking to implement a design with two navigation bars that share a single toggle. The first navbar should include the logo, email icon, and a search box, while the second navbar is reserved for additional links. On smaller screens, when the toggle ...

Using the JQuery Library, you can implement two submit buttons that either open in a new tab or submit

I am facing a situation where I have a FORM containing two submit buttons. My requirement is that when the first button is clicked, the form should submit on the same tab. On the other hand, if the second button is clicked, it should proceed to open a new ...

Is it possible to modify this code to accept multiple IDs at once?

I'm attempting to create a form in JavaScript where, upon entering the necessary details and clicking submit, the user's email client opens with the information pre-filled for easy sending. However, I am facing challenges as my code involves mult ...

Fill your HTML form effortlessly using data from Google Sheets

I am relatively new to this topic, but I'm seeking a solution to populate an Apps Script Web App HTML dropdown form with names directly from a Google Spreadsheet. At the moment, I've managed to retrieve an array of names from column A in my sprea ...

Is there a way to showcase Laravel images on a live server efficiently?

After successfully developing a Laravel app on my local machine, complete with visible images, I encountered an issue upon deployment to the live server where the images were no longer displaying. My hosting setup involves a 'public_html' folder ...

The Mat-paginator is refusing to align to the right edge when scrolling the table horizontally in an Angular application

https://i.sstatic.net/l0cZ4.png Overview: My Angular component features a table with Angular Material's mat-table and paginator. Despite fetching data from a source, the paginator fails to float right when I scroll horizontally. Sample Code: <!- ...

What is the best way to choose a specific div within a container that contains additional HTML elements?

I am facing an issue with selecting the second div tag within a section that contains 2 divs and an img tag. I attempted to use section div:nth-child(2), but it is targeting the second element inside the first div. However, my goal is to select the secon ...

Connecting a hero image in CSS for Flask application: a step-by-step guide

Adding a hero image to my Flask app page has been challenging. Here is the directory structure of my Flask project: -static |--css_files |--my.css |--images |--img.jpg -templates |--layout.html In order to incorporate a hero image, I have includ ...

When hovering over it, an element within an li tag appears larger than its parent element

I'm currently working on a project for my school classes and running into an issue with CSS. I'm trying to enclose everything in boxes, but it's proving to be quite challenging. The main problem I'm facing is that when I hover over the ...

Switching the angularjs variable from html; a definitive guide

How can I update a variable in an AngularJS controller using JavaScript when a specific HTML element is clicked? For instance: angular.module('app',[]) .controller('appController', function($scope, $http){ $scope.on ...

Monitor the element's height for any changes and update it accordingly on a separate element

Is there a way to accomplish the following: I currently have a navigation bar with the class of "navbar-fixed-top", and I've also added a style of min-height: 50px; Beneath the navigation bar, I have a content section with a class style of padding-t ...

Issues with Collapse Feature on Bootstrap 3 Navbar

I need your help with a problem I'm facing. The navigation bar is not collapsing when I click the link in mobile view. Check out this video for more details: https://www.youtube.com/watch?v=2dBpcFMjqY0 ...

Tips on getting your card to stay at the top

Screenshot of webpage HTML (EJS): In the HTML file, look for the section after <%- include("navbar.ejs") -%> inside the body tag. The ".cardholder" contains "anime-card" templates (card.ejs). The first and last div within ".cardholder" are ...

How to set up a Carousel as the background within a div using Bootstrap 5

I'm attempting to create a visually appealing layout by showcasing a Carousel component behind some text. The idea is to have scrolling and fading images with a prominent header overlaid on top of them. I want the carousel images to be contained withi ...

Achieving bottom alignment for an element within a flex item: steps for success

I am dealing with a flex container that contains three flex items, each of which has a link that needs to be aligned at the bottom (all links should be bottom middle-aligned). The flex-items are stretched and do not have a fixed height, similar to the fle ...

Implementing NextJS dynamic routing with component dynamicity

I need to develop 3 dynamic pages, each with its own unique render component. // components/AboutPage.js export default function AboutPage({ template }){ return <h1>{template}</h1> } // components/ContactPage.js export default function Conta ...

Determining the Number of Form Values Equal to 0 Using jQuery

$("#scorecard").change(function() { var total = 0; $("#scorecard :checked").each( function() { if(parseInt($(this).val()) === 0) { total += 1; } else { total += 0; ...

What is the best way to create a single HTML file that can showcase several different pages?

I am just starting out in web design, and I am currently working on a hobby project which is an e-commerce site. My issue is that I don't want to manually link every single product page. This would result in a large number of HTML files. Instead, I w ...

The lobster custom font is malfunctioning in Internet Explorer

I am trying to use the unique font called lobster. After downloading the lobster.woff2 file, I stored it in the font folder. In my custom CSS, I added the following: @font-face { font-family: 'Lobster'; font-style: normal; font-weight: 40 ...