Disabled screen rotation -> hidden background

I tried implementing a media query to "lock" the orientation on my mobile site, but unfortunately, my background image isn't displaying at all.

After adding the media query, I included my stylesheet using the link:

CSS

body {
    padding:0;
    margin:0;
    font-family:Open-sans;
    background-repeat: no-repeat;
    background-image:url('paintingOg.gif');
    background-color:grey;
    background-size:100%;
}

@media (orientation: portrait) {
  body {
    transform:rotate(-90deg);
    background-image:url('paintingOg.gif');
  }
}

HTML

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="Lmob.css">
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js"></script>
</head>
<body style="background-image:url('images/paintingOg.gif');">
<h1 id="orientation">orientationchange Not Supported on this Device.      </h1>

 <script>
 $( window ).on( "orientationchange", function( event ) {
  $( "#orientation" ).text( "This device is in " + event.orientation + " mode!" );
});

// You can also manually force this event to fire.
$( window ).orientationchange();
</script>

Answer №1

After much trial and error, I finally discovered a script that solves my issue. The code snippet below functions correctly with a background image, although it doesn't completely "lock" the orientation.

body {
    padding:0;
    margin:0;
    font-family:Open-sans;
    background-repeat: no-repeat;
    background-image:url('images/PaintingOg.gif');
    background-color:grey;
    background-size:100%;
}

@media screen and (min-width: 320px) and (max-width: 767px) and (orientation: portrait) {
  html {
    transform: rotate(-90deg);
    transform-origin: left top;
    width: 100vh;
    overflow-x: hidden;
    position: absolute;
    top: 100%;
    left: 0;
  }
}

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

Is it possible to merge several blobs into one zip file using JSzip?

When attempting to download multiple images as a single ZIP file, the result is receiving separate zip files instead. The console log shows that the 'urls[]' array contains different arrays. const fileURLs = window.URL.createObjectURL(result);// ...

Learn the process of using calc to rotate images on hover with CSS and Jquery

Is there a way to implement the rotate on hover function for images, similar to what is seen on this website under 'our Latest Publications'? I attempted using calc and skew, however, I was unsuccessful in achieving the desired hovering effect o ...

Retrieving location data using the Google Maps geocoder

Could someone help me with this issue in my code? function getLocationName(latitude, longitude) { if (isNaN(parseFloat(latitude)) || isNaN(parseFloat(longitude))) { return false; } var locationName; var geocoder = new google.maps. ...

How can I activate a radio button by its corresponding label using Selenium?

After diving into the world of automation with Selenium in C#, I find myself faced with a challenge. I need to automate clicking on a specific radio button on a website based on the text of the associated label. What makes it even more interesting is that ...

When the visitor is browsing a particular page and comes across a div element, carry out a specific action

I am trying to determine if I am currently on a specific page and, if so, check if a certain div exists in that page. Here is what I know: To check if a specific page exists, I can use the code if('http://'+location.hostname+location.pathname+& ...

Best Practices for Integrating PHP Code into an HTML File for Contact Form Placement

My current setup involves an html file named index.html, which contains the code for my contact form fields such as name and email. Is there a way to include PHP code in this file without converting it to index.php? ...

Tips for keeping the footer consistently at the bottom of the page without using a fixed position (to avoid overlapping with the main content)

I've been struggling to keep the footer at the bottom of my webpage. I came across a solution online suggesting to use fixed CSS positioning. However, when I applied this fix, the footer ended up overlapping with the actual content on the page. Is the ...

Troubleshooting an issue with my JQuery code in Internet Explorer that does not occur in

Hi everyone, I'm having some trouble with the code below. It seems to be working fine in Firefox and other browsers, but not in IE. I've been checking for syntax errors but can't seem to find any. Any advice would be greatly appreciated! $( ...

Center the text within the div and have it expand outwards from the middle if there is an abundance of text

I have a div that is in the shape of a square box and I want it to be centered. No matter how much text is inside, I would like it to remain in the middle. I am using JQuery to create my square box and would like to center it using CSS. Here is my code: &l ...

Issue with jQuery: addClass not toggling within an IF statement

Is there a way to dynamically add the class "disable" to an anchor tag when a user selects the radio button labeled "Remove"? Currently, in the provided fiddle, the class is added as soon as the page loads. I have included code in the script that successf ...

Utilizing R to Extract Data from HTML Webpages

I am currently extracting flight schedules from JFK's website. You can find the link to access the flight schedules right here; My initial approach involves inspecting a specific field of each flight and recording its xpath. The purpose is to first e ...

What is the best way to ensure that my search box is responsive in HTML and CSS while also horizontally centering the search_box div?

Question 1: I need assistance in making this search box responsive. Every time I try to adjust the screen width, the button ends up below the input field. How can I resolve this issue? Question 2: Is there a way to horizontally center the div class=" ...

The initial ajax request successfully connects to the file, but encounters a 404 error upon the second attempt

I am currently encountering an issue with a jQuery post function. The function is designed to run multiple times and then stop, which it has successfully done in the past. However, now the problem arises when the function tries to execute itself again afte ...

Is it possible to choose a complete HTML element within NetBeans?

Currently using netbeans 7.1 and curious about the possibility of selecting an entire HTML element such as a div tag. If I wanted to select the inner div for deletion: <div id="outer"> <div id="inner"> This is inner Content </ ...

Model change event in Backbone not triggered following model setting

I tried a different approach and used $.ajax() for an ajax file upload because I couldn't quite figure out the "backbone" way at the moment. The new picture has been successfully uploaded and the ajax request returns the new backbone model in JSON for ...

JavaScript isn't functioning properly after UserControl is loaded via Ajax

Thank you, Stilgar for helping me solve my issue. I created a javascript file and placed all my code in it. After adding this file to the UserControl and retrieving the UserControl's html, I used $("#DivID").html(UserControlHTML). Now everything is wo ...

Combining multiple JSON objects in an array into one single object with the help of jQuery

My array consists of JSON objects like the ones shown below: [{ "Name": "Nikhil", "Surname": "Agrawal" }, { "profession": "java developer", "experience": "2 years" }, { "company": "xyz", "city": "hyderabad" }] What I aim to achiev ...

Discrepancy in div height between Chrome/Edge and Firefox browsers

I am currently in the process of designing a straightforward website layout that includes a navigation bar at the top. The main focus is on an image that needs to stretch from the bottom of the navbar to the bottom of the window, filling up the entire scre ...

Guide on modifying CSS properties when hovering over the parent element

I am working with a table structure like this: <table> <tr><td class="momdad"><i class='glyphicon glyphicon-cog'></i> Hello </td><td> Mom </td></tr> <tr><td class="momdad">< ...

experiencing a problem with the scrollTo() function

I am encountering difficulty in finding the correct X and Y coordinate values to move an image using mouse scroll within a div. I have included my sample code below. I have successfully managed to scroll the image without using a div. Can anyone assist m ...