Is it possible for a container to be restricted by a specific maximum width in a media query?

I'm currently utilizing flexbox along with media queries to define maximum and minimum widths for my elements. Everything is running smoothly so far, but in order to achieve the desired layout at a min-width of 1000px, I had to introduce an additional container for two elements to be displayed in a column layout within the row layout applied to the rest of the page.

This setup works well, however, once the width falls below 1000px, I want the container to disappear and have the normal rules apply to the affected elements. I've attempted setting the container to display:none, but that simply removes the elements altogether. I'm struggling to find a solution to this issue as it's quite specific and hasn't been addressed yet.

Here's how it appears above 1000px:

Below 1000px:

And when viewed on iPhone/Tablet (largeContainer disappears behind the #content container):

#content {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.articleImage {
  order: 1;
  width: 48%;
  margin-left: 10px;
  height: 250px;
}

article {
  position: relative;
  text-align: center;
}

article a {
  color: white;
  text-decoration: none;
  position: absolute;
  top: 35%;
  bottom: 50%;
  transform: translate(13%, 50%);
  font-weight: bold;
  font-size: 1.5em;
  text-shadow: black 1px 1px 2px;
  padding: 2px;
}

article img {
  width: 100%;
  border-radius: 10px;
}

.reasons {
  order: 2;
  border: solid 1px #f77f00;
  border-radius: 10px;
  margin-left: 10px;
  margin-bottom: 10px;
  padding: 10px;
}

@media only screen and (min-width: 1000px) {
  #content {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .largeContainer {
    display: flex;
    flex-direction: column;
    width: 26.1%;
  }
  .articleImage {
    order: 1;
    width: 100%;
    height: auto;
  }
  article {
    font-size: small;
    margin-right: 10px;
  }
  article a {
    position: absolute;
    top: 25%;
    bottom: 50%;
    transform: translate(5%, 50%);
  }
  .reasons {
    order: 2;
    font-size: .85em;
    width: 100%;
    height: auto;
    border: solid 1px #f77f00;
    border-radius: 10px;
  }
}
<div id="content">
  <div class="largeContainer">
    <div class="articleImage">
      <article>
        <a href="https://www.theodysseyonline.com/20-reasons-should-eat-mac-cheese" target="_blank">20 Reasons You Should Eat
                          <br>Mac and Cheese Right Now</a>
        <img src="https://th.bing.com/th/id/OIP.TRKuAA8Nt1iBs76N6HDM-AAAAA?pid=ImgDet&rs=1" alt="Fabulous Mac">

      </article>
    </div>
    <div class="reasons">
      <h3>What's so Great about Mac and Cheese??</h3>
      <ol>
        <li>It's a wholesome dish</li>
        <li>Cheese is good for the soul</li>
        <li>Just look at it</li>
        <li>It'll make you the star of any potluck</li>
      </ol>
    </div>
  </div>
</div>

Yes, it's a landing page dedicated to Mac and Cheese! In this scenario, I would like the example to showcase the elements in a row similar to the primary container when the width is under 1000px, yet it's not resetting even though .largeContainer isn't defined in the main CSS code. Your assistance is greatly appreciated!

Answer №1

If someone else comes across this same issue in the future:

I initially hoped to avoid adding extra media queries to adjust the layout for specific widths, but that turned out to be the only viable solution. I ended up incorporating queries targeted solely at the elements affected and made minor tweaks to keep it straightforward.

Above 1000px

760px-1000px

662px-760px

Below 662px

.largeContainer {
  display: flex;
  margin-bottom: 10px;
}

.articleImage {
  order: 1;
  width: 48%;
}

.reasons {
  order: 2;
  width: 48%;
}

@media only screen and (min-width: 1000px) {
  .largeContainer {
    display: flex;
    flex-direction: column;
    width: 28.1%;
    margin-top: 10px;
  }
  .articleImage {
    order: 1;
    width: 100%;
    height: auto;
  }
  .reasons {
    order: 2;
    font-size: .823em;
    width: 93%;
  }
}

@media only screen and (max-width: 760px) {
  .largeContainer {
    display: flex;
  }
  .reasons {
    order: 2;
    width: 100%;
  }
}

@media only screen and (max-width:662px) {
  .largeContainer {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  .articleImage {
    width: 100%;
    font-size: 1.5em;
  }
  .reasons {
    width: 100%;
  }
}
<div class="largeContainer">
  <div class="articleImage">
    <article>
      <a href="https://www.theodysseyonline.com/20-reasons-should-eat-mac-cheese" target="_blank">20 Reasons You Should Eat
                        <br>Mac and Cheese Right Now</a>
      <img src="https://th.bing.com/th/id/OIP.TRKuAA8Nt1iBs76N6HDM-AAAAA?pid=ImgDet&rs=1" alt="Fabulous Mac">
    </article>
  </div>
  <div class="reasons">
    <h3>What's so Great about Mac and Cheese??</h3>
    <ol>
      <li>It's a wholesome dish</li>
      <li>Cheese is good for the soul</li>
      <li>Just look at it</li>
      <li>It'll make you the star of any potluck</li>
    </ol>
  </div>
</div>

Since I can't eliminate .largeContainer from other queries given its presence in the HTML, I simply adjusted it to function properly across different widths. Hopefully, this explanation benefits others as well! Included photos for a comprehensive view of the layout

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

Access Silverlight to open Windows Explorer

Is it possible to launch Windows Explorer to a specific folder from a Silverlight application running in a browser? Also, is there a method to retrieve the machine name within a Silverlight app? ...

Upon clicking the 'Add Image' button, TINYMCE dynamically incorporates an input

I am in search of creative solutions to address an issue I'm facing. Currently, I am utilizing TINYMCE to incorporate text into my webpage. However, I would like to enhance this functionality by having a feature that allows me to add an image along w ...

Using DOMParser() eliminates whitespace

Basic code example: const parser = new DOMParser(); const foo = parser.parseFromString(<p> Foo</p>, 'text/html'); console.log(foo); This results in https://i.sstatic.net/8E2br.png Why have all the leading empty spaces before " ...

Difficulties with integrating tooltips into SVGs

Being a minimalist, I am facing restrictions while working on a website. I desire interactive tooltips to appear when users hover over specific sections of my SVG. However, I also want to incorporate this interactivity within the SVG itself. The challenge ...

What is the best way to extend an image to fill the width of a webpage?

Can you advise me on how to expand the image to fit the width of my webpage? If possible, could you take a look at this website: Poklanjam The specific image I am referring to is the one of the city on the left-hand side. What additional CSS code should ...

Strategies for managing the browser's back button with dynamic content

I am currently working on a PHP application that involves presenting users with a form to complete and submit. After the form is submitted, updates are made in the database and the form should no longer be accessible to the user. However, if the user cli ...

Using PhantomJS webdriver in Python Selenium to disable CSS styling

There seems to be some uncertainty surrounding the ability to disable CSS while utilizing the PhantomJS webdriver for Selenium. It has been established that this is achievable with FireFox by adjusting the FireFox profile, but I am interested in doing so w ...

Achieving a layered effect with elements overlapping onto another div

Looking for a way to create a design where the text in id="text-field" overlaps with id="image-field". Need some guidance on how to achieve this effect. Any help is appreciated. <!DOCTYPE html> <html> <body> <div class=" ...

Getting multiple values from a multi-select dropdown in Angular 6: a step-by-step guide

Take a look at my code snippet below: <select multiple [(ngModel)]="myModelProperty" name="category" (change)="catFilter($event.target.value);hName($event.target.value);" class="form-control"> <option>Select Cat</option> ...

Tips for securely sending hidden data in a Django POST form

In the process of developing a chat website, I am encountering an issue where I need to include invisible information within the message form in order to specify the recipient's username and successfully send the message. I am seeking suggestions on h ...

Incorporate a video within the royal slider feature

Next is my deluxe slider code. This slider displays only images but I am looking to incorporate video as well. I have searched online and tried different solutions, but haven't found one that works for me. Can someone please guide me on how to achieve ...

What could be causing my Bootstrap datepicker to malfunction?

A while ago, my Bootstrap datetimepicker component was functioning perfectly in my code. However, it has suddenly stopped working and I am seeking assistance to get it running smoothly again. Below is the HTML code snippet: <script src="https://cd ...

Switch the cursor to display the magnifying glass icon for zooming in and out

I am curious about how to modify the cursor shape to display a zoom in and zoom out symbol. Changing the cursor to indicate busy or wait status is something I am familiar with, document.manual_production.style.cursor='wait'; However, I am unsu ...

Display updated text on hover over button panel

Is it possible to achieve the following using only CSS without any JavaScript? The desired outcome is a div containing two font awesome icons aligned to the right side. Specifically, I am looking for: - Icon of a pen that reacts on mouse hover - Icon o ...

How can I create a fixed class="form-row" and align a label and textbox in a horizontal line?

I encountered an issue with my simple bootstrap form that contains the following fields: The Labels and text box are not aligned properly in a straight line. When adjusting the size of the Notes field, it affects the positioning of the other fields causin ...

Is it possible to retrieve the value from the searchbar on the server?

I'm seeking assistance on how to retrieve the user-entered value from a search form on my HTML page in my server.js file. I understand that the name/value pair will be cityCode=something, but I'm unsure of the next steps. HTML: <form c ...

Ensuring that the two columns in a responsive grid have equal heights is essential for maintaining a

I am currently working on a responsive website with a main content area (.content-wrapper) and a sidebar area (.search-listing). My goal is to make sure that both columns have the same height. I attempted to achieve this using the following jQuery code: j ...

Tips for updating input placeholder text using CSS

Is it possible to change the placeholder text of an input textbox using only CSS? Here's the HTML code snippet: <div class="col"> <input class="form-control" type="text" placeholder="" id="m ...

Token Error in Angular App

I've encountered a sudden issue with my leaflet map. Every time I click on the map, a marker is added to the same coordinates despite my efforts to remove them using a function. Even though the markers-array is emptied, the markers remain visible on t ...

The backdrop-filter in tandem with mask-image is not functioning as anticipated on the Chrome browser

I am facing an issue with the interaction of the mask-image and backdrop-filter attributes on Chrome v116. My goal is to create a gradient-blur effect over text. While this works correctly in Firefox, Chrome only displays a solid white block. This is how ...