Only tablet devices should display the changes

I set the body background color to blue on my webpage. However, I want it to change to orange when viewed on tablets or mobile devices, while keeping the blue color unchanged when resizing the browser window on a PC. Is this achievable?

Answer №1

If you want to adjust the width, simply modify the CSS tag, but keep in mind that this change will apply across all devices.

@media only screen and (max-device-width: 1440px) {

To determine whether a user is using a tablet or another specific device, you can utilize Javascript to identify the device and load the appropriate CSS accordingly.

Check out this code for reference: [link]http://davidwalsh.name/detect-ipad[/link]

The challenge lies in the fact that there are countless devices in use today, requiring you to account for each one individually.

// For regular web clients 
var isiPad = navigator.userAgent.match(/iPad/i) != null;

// For iPad developer UIWebView
// Credits to Andrew Hedges!
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);

Answer №2

Have you tried using a CSS3 Media Query like the one shown below?

/*Tablet Screen Size*/
@media only screen and (max-device-width: 1024px) {
    body{
       background-color:blue;
    }
}

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

Effectively managing null values returned by FirebaseInstanceId.getInstance().getToken()

How can we ensure that the getToken() function returns a valid token id in a reliable and secure manner? I have come across different approaches used by developers: Using a while-loop to continuously call getToken() until a non-null value is returned Im ...

Unexpected malfunction in CSS Grid within Flexbox layout

After extensive testing, I have found that the .articleWrapper for post child items scales correctly when used on its own. However, as soon as I place this .articleWrapper inside another wrapper-element with display: flex, it loses its ability to scale hor ...

What could be causing my tab code to not function flawlessly?

I am attempting to implement a tab concept on my website. For example, the tab names are Monday...Tue.. up to Sunday. Each tab contains an image file based on the days (size 460*620). When I run my page, it shows all images, but what I need is for the imag ...

:before pseudo-element causing interference with child elements

Struggling to understand how an absolutely positioned :before element works. I need a large quote mark to be placed behind a testimonial. I opted for a :before element because it is a font, making it scalable for retina displays and saving an extra HTTP re ...

What is the best way to showcase a product's star rating using a variable or input from the user?

I'm seeking a solution to dynamically display a star rating in Spring Boot/Java without specifying a fixed value. While I can show star ratings with a set value, how can I update the rating based on an average of user ratings? Most tutorials only cove ...

Two-column layout with consistent height vertically, but varying heights on individual rows

By using JavaScript, I am able to ensure that two columns have equal height. The left column contains user input which can vary in length, causing some columns to have more content than others. My current issue is that there are multiple rows instead of ju ...

Tips for ensuring compatibility of CSS in IE7 and IE8

Despite using the following styles to dynamically display alternative colors in my HTML code, I am facing compatibility issues with IE7 and IE8. Surprisingly, everything works perfectly fine on IE9 and above. It seems these styles are not supported by IE7 ...

The CSS on the maps infobox is not rendering properly when an icon is clicked

Hey everyone, I'm in the process of creating a travel blog on WordPress and have encountered some issues with the CSS on my site. I've included maps and tables that look fine in my fiddle, but when I transfer them to my website, they appear disto ...

Missing NDK stack backtraces in Fabric Crashlytics due to incomplete frames

I have been working on an Android Studio project with multiple native shared libraries implemented. To enhance the crash reporting capability, I decided to integrate Crashlytics NDK support and uploaded symbols to Fabric by following the steps outlined in ...

Animating text so it moves to a random spot within a circular div

I hope everyone is doing well. For my assignment, I need to animate an image to a circular div container at a random location. Currently, I have already completed this task. You can view my work here: jsfiddle.net/f4p6b/137 However, the issue I am faci ...

How can I set a background image to automatically adjust to the width of the window, be full height, allow for vertical scrolling, and

How can I set a full-screen background image that adjusts to the body width without horizontal scrolling, maintains height proportionate to width, and allows for vertical scrolling? Here is my current code: html, body { margin: 0px; padding: 0px; } bo ...

What is the best way to define my background image using markup language?

I'm facing a challenge with some code that I didn't write which includes a background-image. While I want to maintain the identical appearance, I prefer to set the image in my markup rather than CSS. However, I'm unsure of how to do this. T ...

Incorrect item triggered in Bootstrap 4 dropdown menu

I'm currently tackling an issue with a navigation bar that includes two items with drop-down menus. The first drop-down works flawlessly, but the second one always ends up triggering the first. I've conducted tests after removing any additional s ...

Executing a function when ng-init is set to true in AngularJS

Greetings! I am working with the following piece of code: html: <div class="portlet-titlebar" ng-click="toggleCollapsed(portlet, $event)" ng-class="{current: hover}" ng-init="hover = false" ng-mouseenter="hover = hoverIn()" ng-mouseleave="ho ...

Transferring a pair of files simultaneously from an android device to a python server

I'm currently looking into writing code that will allow me to transfer files from a directory on my Android phone to a Python server on my computer. I am wondering if it's possible to establish a connection between a Java socket client and a Pyth ...

Understanding the behavior of CSS float (even after thorough examination of W3C documentation)

I am currently facing an issue related to the float property and have provided a snippet of code below for reference. My goal is to achieve a two-column layout using floats. While I am familiar with other methods to achieve this layout, I am specifically i ...

Adjust default SMS application on Android 4.4 without needing user confirmation

Is it feasible to alter the default SMS application on Android 4.4 without the user's awareness? I am attempting to achieve this on a ROOTED Galaxy S5 by utilizing reflection and invoking system methods. Here is the progress I have made so far: I hav ...

Styling with CSS: Spinning picture for mobile displays

http://jsfiddle.net/ajxqnqpo/ I'm facing a challenge with displaying a rotated image on full screen for mobile devices without using fixed width or margin properties. The image should ideally have a 10px margin from each side. The issue arises becau ...

Presenting a unique navigation feature that displays the menu simply by hovering over it,

I'm utilizing bootstrap to create a horizontal menu in HTML <div class="btn-group""> <div class="btn-group"> <button type="button" data-toggle="dropdown" class="btn btn-inverse dropdown-toggle>About Us<sp ...

Tips for ensuring the Search button always remains alongside the input bar during resizing with percentages

I've been trying to figure out why the search button is still showing at the bottom left and creating an "l" shape even though I'm using style="overflow: hidden; padding-right: .5em;". Does anyone have any ideas as to what might be causing this i ...