Troublesome CSS media queries failing to meet expectations

I am facing an issue with two divs that are supposed to be 368px x 228px and sit next to each other. Despite my attempts to apply media queries and run tests, I am unable to resolve the issue. Can someone guide me on how to fix this?

Below is my code:

<style type="text/css">

  .block-content-right {
    background-color:#e0e620;
    flex:1;
   }

   @media (max-width: 600px) {
    .field__item {
    width: 100%; 
      }
    }

    @media (min-width: 400px) {
     .field__item {
     width: 100%; 
       }
    }

 </style>

<div class="block-content-right">
<p>The people the people the people</p> 
</div>

<div class="field__item">
<img src="blah blah.jg";> 
</div>

https://i.sstatic.net/9dQKV.png

Would appreciate some assistance. Thank you.

Answer №1

Your media queries are functioning correctly, but one of them will always be active.

It seems like you might have intended for the following:

@media (max-width: 600px) and (min-width: 400px) {
  /* This styling will apply when the screen width is between 600px and 400px */
.field__item {
width: 100%; 
  }
}

Alternatively, you could use this approach:

@media (max-width: 400px) or (min-width: 600px) {
  /* This styling will apply when the screen width is NOT between 600px and 400px */
.field__item {
width: 100%; 
  }
}

Note: To test the effect, consider using a different CSS property as 'width: 100%' may not visibly change anything due to divs' default full width appearance. You can try 'border:5px solid red;' instead.

Code for stacking elements in narrow screens: (Elements will align side-by-side on wider screens)

@media (min-width: 800px) {
  .half-width {
    display: inline-block;
    width: 49%;
  }
}
<img class="half-width" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Zinnia_elegans_with_Bombus_01.JPG/640px-Zinnia_elegans_with_Bombus_01.JPG" />
<div class="half-width">Here is some text. More and more and more text. And more and more text. And more and more text. And more and more text. And more and more text. And more and more text. And more and more text.</div>

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

The oval shape of a Canvas circle in HTML5 is due to its width and height properties

var qcanvas = $('#canvas'); var canvas = ctl_canvas[0]; var context = canvas.getContext('2d'); qcanvas.css('border', '1px solid black'); qcanvas.css('width', 400); qcanvas.css('height', 75); Afte ...

Discover the technique of accessing HTML/CSS toggle switch value in Golang

I am attempting to incorporate a toggle switch into my webpage. I followed this specific tutorial for guidance: w3schools.com Currently, I have set up my HTML file with a button and the toggle switch. Additionally, I configured my web server in Go to lis ...

Incorporating Google Maps Embed: Transforming iFrame into a clickable link on both iOS and Android

My website features an embedded Google map showcasing the location of my business. I am trying to enable users viewing the website on iOS/Android devices to click on the map and have it open in the native Google Maps app using the URL schema comgooglemaps ...

Individualize participants and thwart repetition

I need help separating 3 radio players using HTML code and ensuring they remain distinct entities. What code should I use between them to achieve this? For example, all 3 radio players end up looking like the last one at the bottom if not separated correc ...

My JavaScript/Jquery functions are not running as expected

I need some help creating a simple image rotation feature. I have a folder named comics where the images are stored locally with names like comic_(number). However, when I click my buttons, nothing happens. The previous button doesn't even get disable ...

Struggling to locate the distinctive XPath for the button

I am facing a situation where the XPath is non-unique and identifies 3 elements on the page that change positions upon refresh: <div class="col-xs-12 Hover"> <button data-testid="continueCheckoutButton" ng- class="continueDellMetricsC ...

Activate jQuery when a click event occurs to modify the CSS of a specific

I've managed to create 2 buttons labeled SHOW & HIDE, along with a DIV containing some content. My goal is for the first button to expand the width of the content DIV upon clicking, hiding itself in the process and revealing the second button simultan ...

Issues with Javascript Date Function malfunctioning

I'm having trouble getting the text 'Oct 09, 2012' to display properly. Instead of running the function correctly, a bunch of unnecessary date text is showing up. Can anyone figure out what I'm doing wrong? Feel free to experiment with ...

Using the rvest package to extract data from a password-protected website without the need to log in every time the loop iter

My goal is to extract data from a password-protected website using the rvest package in R. Currently, my code logs in to the website in each iteration of a loop, which will be repeated approximately 15,000 times. This approach seems inefficient, but I have ...

Provide alternative styling through css in instances where the Google Books API does not provide an image

How can I modify the CSS code to display the author and title of a book when there is no image available from the Google Books API? Currently, users see a custom image linked here, but it's not clear what it represents without the name and author inf ...

Access a designated tab within a CSS-designed tab system

Can anyone offer some assistance? I currently have a tab structure created using CSS. The first tab is set as the default when the page loads. I am looking to create a link from another page that will take users directly to the page with the tabs and ope ...

Ways to increase the values in a textbox

My task involves handling checkboxes that are populated with data from a database. The goal is to have certain checkboxes pre-checked based on the retrieved data, and if any are not checked, their values should be entered into a textbox. For instance, con ...

What is the best way to save Arabic text in a MySQL database from an HTML form using PHP?

I've been searching extensively, but have had no luck! >> Following the PHP connection I included: mysql_set_charset('utf8', $conn); >> The form input tag has the attribute: accept-charset="utf-8" >> I confirmed that the d ...

Combine a fully operational webpage (html, css, js) within a React framework

Currently, I have a standalone HTML, CSS, and JS page that functions independently. The HTML file loads JS and CSS from CDNs as well as local files. Now, I am looking to integrate this standalone page into a Next.js/React application. At the moment, I hav ...

Ways to create CSS styles dynamically in PHP using database-driven methods

Currently, I am in the process of developing an application that gives users the ability to select different style options within the app. These choices will then be utilized to create a dynamic web page. I am curious about the various methods available to ...

in Vue.js, extract the style of an element and apply it to a different element

Currently, I am using VUE.js 2 in my project. Here is my website's DOM structure: <aside :style="{height : height()}" class="col-sm-4 col-md-3 col-lg-3">...</aside> <main class="col-sm-8 col-md-9 col-lg-9" ref="userPanelMainContents" ...

Secret button concealed within a div, revealing only a helpful hint

On my website, there is a list of items where each item is represented by either a picture or a name enclosed in an <article> tag. Here is an example of how it looks: <article class="client-card"> <p><img width="211" height="106" ...

Is there a way to reference a background-image using "<img src>" syntax?

Why won't the background image display? It only displays as an img src. How can I call the background-image correctly? <body> <div id="page" style="background- image:url(https://storage.blob.core.windows.net/name/image.png)"> ...

What is the best way to retrieve a specific value from a multi-dimensional JSON object array?

I'm struggling to retrieve a value from the JSON object below array(3) { [0]=> object(stdClass)#1 (11) { ["Group"]=> string(2) "18" ["GroupName"]=> string(8) "Wireline" ["Region"]=> string(2) "15" ["RegionName"]=> string(8) "Atlantic" ...

Make the image take up the entire screen in HTML

My goal is to display an image that fills the entire screen. Here's how my HTML code looks: <!DOCTYPE html> <html lang="de"> <head> <meta charset="utf-8" /> <title></title> </head> ...