Struggling with the challenges of utilizing @media only screen to conceal a div in mobile view

I need to toggle the visibility of the "tiled-map" div when viewing on mobile devices, while ensuring that all 3 divs (base-map, overlay-map, tiled-map) within the "map-wrapper" div are displayed on desktop view.

Currently, I am using Bootstrap CSS without any specific CSS class for the map-wrapper div. I initially set its width to 200%, but now I want to adjust it to 100% for mobile view, utilizing a custom CSS segment in Bootstrap. Although I acknowledge that my usage of the mobile-hide class for the tiled-map div may be redundant, as it was part of an experimental approach.

Here is a snippet of the code:

HTML:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<div class="container">
    <div class="row">
        <div class="col-lg-6 col-md-6">
        <div id="map-wrapper" class="mobile-hide" style="width: 200%; height: 600px; position: relative;">
            <div id="base-map"></div>
            <div id="overlay-map"></div>
            <div id="tiled-map"></div>
        </div>
        </div>
    </div>
</div>

CSS:

@media only screen and (max-width: 480px) {
  #tiled-map {
    visibility: hidden !important;;
    display: none !important;
  }
  .mobile-hide {
    width: 100%;
    visibility: hidden !important;;
    display: none !important;
  }
}

How can I tackle this issue?


Updated (Resolved):

<div class="container">
    <div class="row">
        <div id="map-wrapper">

            <div id="map1"></div>
            <div id="map2"></div>

            <input id="searchtxt" class="searchtxt" type="text" style="z-index:100; position: relative; top: 20px; left: 70px; border-radius: 5px; width: 250px; font-family: 'Archivo Narrow', Arial; font-weight: 400;"onkeyup="liveSuggest(this.value)" />
            <div class="dropdown" id="searchResultList" style="z-index:10; position: absolute; top: 50px; left: 50px;font-family: 'Archivo Narrow', Arial; font-weight: 400; width: 300px"/>

        </div>            
            <!-- Pager -->
            <ul class="pager">
                <li class="next">
                </li>
            </ul>  
    </div>
</div>

CSS:

<style>
    head {
        background-color: #473731;
    }
    body {
        margin: 0;
        background-color: #473731;
    }

    #map-wrapper {
         width: 1140px;
         height: 640px;
         position: relative;
         margin: 0 auto;
    }
    
    /* Additional media queries and styling rules here */
    

Answer №1

Check out this interesting demonstration. It's important to note that adjusting the max-width in your media query can cause items to disappear if it exceeds the size of your current screen. Conversely, lowering the max-width below the screen size will reveal the red div.

It's crucial to establish default styles for elements before implementing media queries to ensure proper visibility changes. Make sure your media queries effectively overwrite any existing properties.

Explore this concept further here.

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

Struggles with eliminating Mix from a Laravel-Vue hybrid project

My goal is to streamline the process of adopting new features or releases by removing Laravel Mix from my project. I want to avoid using Mix's syntax or plugins and eliminate the need to contain everything within the webpackConfig method. I have succ ...

Show a notification when utilizing AJAX requests

I consist of two separate files: one written in PHP and the other one in JavaScript and HTML. PHP file : <?php session_start(); //start session $_SESSION['data'] = "The content should be displayed as alert in the JS file"; JS/HTML File: & ...

Setting the maximum length value in HTML dynamically

There is an input field with specific formatting restrictions, such as a maximum length of 6 characters and only accepting numeric values. On blur event, the 6-digit code "123456" is automatically formatted to "12-34-56" and the browser remembers this form ...

Tips for safely storing data in local storage using Angular 5

How can I securely store data in local storage, such as encrypting and decrypting the local storage data to prevent manipulation by other users? If it's not possible with local storage, what are alternative methods for client-side data storage? I&apo ...

Vue .filter doesn't work with reactive data sources

I'm currently working on a project that involves creating a dynamic shipping estimate in a Shopping Cart. The challenge I face is retrieving shipping methods from an API endpoint and making the data reactive to update in real-time based on the selecte ...

Adjusting the width of a <div> element based on window size changes

So I have this Vuejs application that has three divs using CSS grid: a sidebar, a config panel, and a preview. I want to dynamically set the width of the preview div in pixels based on the current screen size and when the screen is resized. To give a bett ...

Tips for effectively transferring date from PHP into JavaScript

I have obtained the current date using a PHP script $time_local_js = date('Y,m,d,H,i', strtotime('now')); and now I need to transfer it into a JavaScript script <span id="countdown"></span> <script type="text/javascri ...

Updating Button Color Based on Input Field Value in EJS

How can I change the color of a button in EJS when the input value changes? <div> <textarea name="mytextarea" id="inputcontent" cols="30" rows="3" style="margin-top: 10px; margin-bottom: 10px; f ...

What could be causing the issue with the functionality of third-level nested SortableJS drag-and-drop?

I am currently utilizing SortableJS to develop a drag-and-drop form builder that consists of three types/levels of draggable items: Sections, Questions, and Options. Sections can be dragged and reorganized amongst each other, Questions can be moved within ...

Analyzing similarities between objects and arrays to find and return the matches

Items {670: true, 671: true} List 0: {id: 669, item_id: 35} 1: {id: 670, item_id: 35} Desired outcome 0: {id: 670, item_id: 35} Is there a way to compare two datasets and return the matching entries based on their ids? ...

What is the best way to manage a brief webhook timeout in a Node.js environment?

The eSignatures API has been successfully integrated into our app, ensuring smooth functionality up to this point. However, an issue has arisen with the webhook function. When a client signs a document, it triggers our webhook cloud function to update our ...

The issue with the smooth scrolling feature in next/link has not been resolved

I am currently facing an issue where smooth scrolling is not working when using next/Link, but it works perfectly fine with anchor tags. However, the downside of using anchor tags is that the page reloads each time, whereas next/link does not reload the pa ...

Tracking user sessions using cookies, not relying on JavaScript like Google does

Currently, I am working in an environment that utilizes PHP on the server side and Javascript on the client side. In order to monitor user sessions, I regularly send a JS PUT request to the server every 5 seconds. This allows me to gather data such as the ...

The efficiency of XSL Template is significantly impacting loading time

Hello there, I am facing a challenge with my webpage's loading speed due to the code provided below. Can you assist me in optimizing it? <xsl:template match="Category" mode="CategorySelectorScript"> <xsl:variable name="ThisCateg ...

Exploring the possibilities of developing WebComponents within Angular using TypeScript

My Angular application was originally created using the default method with ng new project-name". However, for performance reasons, I had to incorporate single standard WebComponents. The JavaScript code associated with these components is stored in a ...

Looking for a way to scroll images without relying on the marquee tag? Whether you prefer using JavaScript, jQuery,

<marquee> <div class="client"> <img src="images/c1.png"/> </div> <div class="client"> <img src="images/c2.png"/> </div> <div class="client"> ...

Encountering an Uncaught TypeError when attempting to read properties of undefined, specifically 'backdrop', while incorporating a bootstrap 5 modal within a react environment

An issue occurred when attempting to display a Bootstrap 5 modal using JavaScript. const handleClick = (e) => { e.preventDefault(); const modalElement = document.getElementById('editUserModal'); const modal = Modal.getOrCreateInsta ...

Ways to insert HTML text into an external webpage's div element without using an iframe

Is it possible to generate HTML and SVG code based on the position of a Subscriber on a web page or within a specific div? I would like to provide some JavaScript code that can be inserted inside a particular div on the page. Using an iframe is not ideal ...

How can I remove the popover parents when clicking the confirm button using jQuery?

I am having trouble sending an AJAX request and removing the parent of a popover after the request is successful. I can't seem to access the parent of the popover in order to remove it, which is causing me some frustration. // Code for deleting w ...

"Utilizing Twitter Bootstrap to create full-width input fields with pre

Presently utilizing bootstrap-2.1.1 In my row-fluid, I have 2 columns with input-prepends inside. Below is a snippet of code: <div class="row-fluid"> <div class="span6"> <ul> <li> <div class="input ...