Struggling with implementing media queries?

Currently, I have my code configured so that one div is visible from 0-992 pixels browser width, and the other div is visible from 993-infinity browser width. When one div is visible, the other is hidden. The visible div contains a video in the code. However, there seems to be an issue with the .mobileVideo class still showing at 992 pixels. It's just that specific pixel range that seems to be broken and I'm struggling to find a solution for it. If my explanation is unclear, feel free to ask for clarification. Below you can find the HTML and media queries used:

<section class="promoVid">
  <div class="container">
      <div class="row text-center">
          <div class="col-md-4">
            <h2>What We Have to Offer</h2>
            <div>
                <span class="decoration_line"></span>
            </div>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean vel massa iaculis, posuere augue et, pharetra ipsum. Suspendisse metus ex, pellentesque id dolor in, vehicula varius tortor. Nam auctor ante nisi.</p>
                <div class="col-sm-10 col-sm-offset-1">
                    <a class="btn defaultBtn btn-block" href="/services">Services</a>
                </div>
          </div>                       
          <div class="video-responsive"><!--hidden-xs hidden-sm-->
                <iframe width="560" height="315" src="https://www.youtube.com/embed/NmeFmmoqzR4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
          </div>
      </div>
  </div>
</section>

<section class="mobileVideo"> <!--visible-sm visible-xs-->
    <div class="container">
        <div class="videoWrapper">
            <iframe width="560" height="315" src="https://www.youtube.com/embed/NmeFmmoqzR4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
        </div>
    </div>
</section>


 @media (max-width: 992px) {
        .video-responsive {
            display: none!important;
        }
    }
    @media (min-width: 993px) {
        .mobileVideo {
            display: none!important;
        }
    }

Answer №1

Make sure to add spaces between your CSS values and !important declarations.
dispaly:none!important should be corrected to display: none !important.

While using !important provides high specificity, it is recommended to use it sparingly. Consider adding more specific rules before resorting to !important. In your case, a simple display: none may suffice.

Regarding the pixel ranges, ensure that the max-width and other values do not overlap by setting them to the same value if needed. For instance, use 992 consistently as shown in my example.

@media (max-width: 992px) {
  .video-responsive {
    display: none;
  }
}

@media (min-width: 992px) {
  .mobileVideo {
    display: none;
  }
}
<section class="promoVid">
  <div class="container">
    <div class="row text-center">
      <div class="col-md-4">
        <h2>What We Have to Offer</h2>
        <div>
          <span class="decoration_line"></span>
        </div>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean vel massa iaculis, posuere augue et, pharetra ipsum. Suspendisse metus ex, pellentesque id dolor in, vehicula varius tortor. Nam auctor ante nisi.</p>
        <div class="col-sm-10 col-sm-offset-1">
          <a class="btn defaultBtn btn-block" href="/services">Services</a>
        </div>
      </div>
      <div class="video-responsive">
        <!--hidden-xs hidden-sm-->
        <iframe width="560" height="315" src="https://www.youtube.com/embed/NmeFmmoqzR4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
      </div>
    </div>
  </div>
</section>

<section class="mobileVideo">
  <!--visible-sm visible-xs-->
  <div class="container">
    <div class="videoWrapper">
      <iframe width="560" height="315" src="https://www.youtube.com/embed/NmeFmmoqzR4?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
    </div>
  </div>
</section>

I hope this explanation is helpful!

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

Increasing counter on the backend using PHP or JavaScript

Having done my research, I am struggling to find a suitable solution for my project. I need a server-side incremental counter that resets daily. The goal is for every website visitor to see the same number on the counter. Is there a PHP script or JavaScr ...

Design a hover zone that allows for interaction without disrupting click events

I am looking to create a tooltip box that appears when hovering over an element, and I want the tooltip to only disappear when the user's mouse exits a specific custom hover area outlined by a vector graphic. My current implementation is working, but ...

Unable to use [audio] playback directly as a callback in jQuery

Review the following code snippet: var music = $("audio")[0]; //doesn't work $("#pbutton").click(music.play); //works $("#pbutton").click(function(){music.play()}); The line that is not functional throws an error in Firefox: TypeError: 'play&a ...

javascript: window.open()

I am currently using VB.NET 2005 and I have a requirement to launch a new browser window using Process.Start(). The challenge is that I need to specify the size of the browser window, for example, height:300 and width:500. Process.Start("firefox.exe", "ab ...

Save the Selenium HTML source code into an HTMLDocument element

Is there a way to save the HTML code fetched using Selenium (via Excel VBA) into an HTMLDocument element? The following example demonstrates utilizing Microsoft Internet Controls and Microsoft HTML Object Library for automating Internet Explorer. Dim IE ...

Adjust the default dimensions of the background image

My CSS file includes the following code: input.myInput { background-image:url('search.png'); background-size:120px 120px; } In my HTML file, I have the following input element: <input type='text' class='myInput' > I ...

Replace the single text area with multiple div elements and update the image within each div

Within the 'Pinctitle' area, there is text that I want to change each time a Pselectorbutton is hovered over with a fading effect. Additionally, I would like the image inside the 'Pselectorbutton' to change at the same time. Currently, ...

Center the text vertically within a card using Vuetify styling

I am seeking a way to vertically align text within a card using Vuetify or traditional CSS in a Vue project. Here is my code: <template> <div> <v-container class="my-5"> <v-row justify="space-between"> <v- ...

Update the button color to transform it from a dull grey when disabled to a vibrant shade

I am trying to modify the button color in my script from grey to green when it transitions from disabled to enabled status. Despite using both the disabled and enabled properties in my CSS and incorporating vue.js (which I am not very familiar with), the c ...

Display button outside of container by utilizing absolute positioning

My objective is to design a comment button that appears next to the text when highlighted and remains fixed in place next to it as the page is scrolled. I have noticed that the button only appears within the padding and not the margin. How can I adjust th ...

Using Selenium to scroll down to an element until its 'style' changes

I'm in the process of scraping a review page similar to this one. While this specific page has only a few reviews, there are others with a larger volume that require extensive scrolling. Upon observation, I noticed that when the page is not complete ...

Steps to make a link that can call a phone number directly from a mobile device

Can an image be designed to initiate a call when tapped on a mobile device? Or perhaps pre-populate the number in the phone dialer? I believe I've come across similar functionality on mobile sites in the past. ...

Having trouble restricting the width of a column in Bootstrap?

I am having trouble adjusting the width of a specific column (Name: link) in my code. Here is what I have so far: <table class="table table-striped table-bordered"> <thead> <th>ID</th> <th>User</th> **<th class="col- ...

Obtain the value of the background image's URL

Is there a way to extract the value of the background-image URL that is set directly in the element tag using inline styling? <a style="background-image: url(https:// ....)"></a> I attempted to retrieve this information using var url = $(thi ...

HTML Troubleshooting Yahoo Mail's Background Color Problem

While developing an HTML email that renders correctly across all platforms, I encountered an issue with Yahoo Mail. The background color and linear gradient are not displaying as expected in Yahoo Mail (tested in Chrome). Despite knowing the best practices ...

Ensuring the responsiveness of CSS and jQuery animations

Issues Encountered: The animation I implemented lacks responsiveness as images and text tend to move around and appear disproportioned on smaller screens. The .moveup class fails to animate properly despite numerous attempts to set up CSS transitions cor ...

Issue with Card Header in Bootstrap 4 Accordion causing non-responsive text on mobile devices

I have been working with a bootstrap 4 accordion. The issue I am facing is that the text in the card header is not responsive. If the length of the text exceeds the width of the card header, it ends up displaying outside. <div class="card"> ...

Combining HTML elements to form a fresh element

Consider the following code snippet for selecting and displaying a date: <div> <input type="text" class="txt txtDate"/> <input type="button" class="btn btnDate" value="Select from Calendar&q ...

Retrieving the text from the selected radio button

Seeking to retrieve the text of the "checked" radio button. The HTML structure is produced by a template and displayed as follows: <input type="radio" name="whatever" value="Y" checked="checked" >Yes</input> <input type="radio" name="whatev ...

Building a collapsible table using Materialize CSS

I am struggling to recreate a similar setup as this query but with materialize css instead. Materializecss Collapsible seems like it should be simple to integrate into a table structure, but I'm unsure of the process. If someone could offer a practi ...