Is it possible for media queries to effectively support mobile devices?

I have a specific requirement for my

<input type="number">
element where I need the up and down spinner buttons to be displayed for selecting the next value. However, on mobile devices, these spinner buttons are not visible. To address this issue, I want to create separate up and down buttons that will only appear on mobile devices. I came across a suggested solution in a Stack Overflow post, which recommended using a media query to show a DOM element when the screen size is small. However, I realized that if a user simply resizes the browser window on a PC, both the spinner buttons and the custom up and down buttons would be displayed. To tackle this challenge, I attempted the following:

@media-desktop (min-width: 1px) {
  .desk {
    visibility: visible;
  }

  .div-only-mobile {
    visibility: hidden;
  }
}

Unfortunately, this approach resulted in both divs being visible on both PC and mobile devices.

My question is, how can I effectively display a DOM element exclusively on a mobile device while hiding it on a PC?

Thank you for any guidance or suggestions.

Answer №1

This code snippet should do the trick

.desk {
 display: block;
}


.div-only-mobile {
    display: none;
}

@media only screen and (max-width: 768px) {
        .desk {
            display: none;
        }

        .div-only-mobile {
            display: block;
        }
    }

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 addClass, removeClass, and css functions in jQuery are malfunctioning

I stumbled upon this website and I am looking to switch the font color from black to white. I attempted various methods but unfortunately, none of them seemed to work: Implementing jQuery's addClass function (to add a class to the SPAN tag) Uti ...

Creating a menu bar in jQuery that functions similarly to tabs, but without the need to change divs

Currently, I am exploring ways to create tab functionality similar to jQuery's tabs plugin but without the need to switch between DIVs. Essentially, I am looking for a jQuery plugin that solely handles rendering the tab bar and allows me to designate ...

Display elements that are positioned absolutely within a container with scrolling overflow

My modal contains a scrollable list with many items that have absolute positioned elements causing overflow within the modal. How can I ensure that the absolute positioned elements are visible in this scenario? .modal { width: 300px; border: 1px ...

jQuery method for implementing alternating row colors that are not sequential

Starting from scratch here. I've fetched a table from a remote server where odd rows are white and even rows are grey. Some rows have been hidden: $("td").filter(function(){ return $(this).text()=='R1';}).text('Row1'); //white $(" ...

Issue with presenting the scrollbar alongside the Dropdown menu

I'm in the process of creating a menu with multiple items and sub-items. I'd like to have a scroll bar appear alongside the items if they become too numerous. The same goes for sub-menus and so forth. Check out this example to see what I mean. ...

Summernote information embedded with HTML elements

I just started using the summernote text editor and I'm trying to figure out how to extract the content from the textarea without all the HTML tags. This is what I have in my code: <textarea class="summernote" id="summernote" ng-model="blog.c ...

Is there a way to track and detect alterations to an element using JavaScript or jQuery

Can I detect the addition of a specific CSS class to an element without having to create a new event? ...

Switching the input type from file to text

My request is to have a file input type that is initially set as read-only, yet still allows the user to manually enter the file name in a text box. Is there a way to achieve this? I want to be able to write the file name similarly to how I would input t ...

Display an image with HTML

My current project involves creating a chrome extension that will display a box over an image when hovered, while also zooming the image to 1.5 times its original size. In my research, I came across a similar example. .zoomin img { height: 200px; wi ...

Identify and automatically switch to the mobile site following a selection

Seeking a way to incorporate a redirect on my Joomla site that leads users to a mobile-friendly HTML5 app. After much thought, I've put together the following script: <script type="text/javascript> <!-- if (screen.width <= 800) { ...

Adjust the background hue of the Row in the Table

Is there a way to update the background color of a Table Row? I attempted using "BackgroundColor" but didn't see any changes Any suggestions on how to fix this issue? <TableRow style={{ backgroundColor: "#FF0000" }}> <TableCell& ...

Finding image input loading

When working with the following code: <input type="image" ... onLoad="this.style.opacity = 1" /> Everything seemed to be functioning well in IE, but encountered an issue in Chrome where the onLoad event failed to trigger upon image load. It's ...

Open the overflow div within a table data cell

My goal is to create a drag-and-drop schedule tool similar to Fullcalendar. I have decided to use a table layout with a rectangular div inside each TD cell to represent tasks. <table onDragEnd={dragend}> <tr> <th>0</th> ...

The CSS theme fails to adapt to changes made using jQuery

I encountered a peculiar problem while using a CSS theme with jQuery. After applying a custom CSS theme to a webpage, everything looked fine. However, when I performed certain operations using jQuery - like checking checkboxes causing others to be checked ...

Can ChatGPT Service Error be resolved?

I tried using chatGPT to help me with my HTML code, but every time I opened it I received an error message saying "Failed to get service" Here is the code that I want to make work: <html> <head></head> <body> <script& ...

Chrome is failing to run the keyframe animation transform

This solution seems to function properly on Firefox and Safari, and even on IE! However, it encounters issues when used on Chrome. (It runs smoothly on Firefox and IE, but on Chrome the animation does not display at all!) @keyframes animationFrames{ 0% ...

Is it possible to adjust the height of the navbar in Bootstrap?

Currently, I am in the process of replicating the mac OS navbar and am seeking guidance on resizing the navbar height and adjusting text size to around 12px. This is my first time working with bootstrap, so any assistance would be greatly appreciated. Addi ...

Utilize express middleware for applying CSS styles in web development

How's it going? I've been experimenting with middleware in Express JS, like this: app.get ('/user/:school/:dual', function (req, res, next) {   ......   ...   ...... }); Everything seems to be working fine so far. But when I na ...

Iterate through an array and update the innerHTML content for each value contained in the array

Looking to replace a specific word that keeps appearing on my website, I experimented with various functions and stumbled upon this method that seems to work: document.getElementsByClassName("label")[0].innerHTML = document.getElementsByClassName ...

What is the solution to making flexbox align-items flex-end work in WebKit/Blink?

I'm attempting to embed one flexbox within another flexbox. The outer box is aligned vertically: +------+ | | +------+ | | | | | | +------+ The top section adjusts to fit the content with flex 0 1 auto, while the bottom half occu ...