The issue I'm facing is that the "background-image" is not resizing automatically when changing orientation in CSS on

I've encountered an issue with displaying an image in the DOM that is sized based on the screen height. While this setup works flawlessly on most browsers and devices I've tested, Safari iOS 7 seems to be causing some trouble.

Specifically, in Safari iOS, the image loads correctly initially for the current orientation. However, when switching between portrait and landscape modes, the image fails to resize according to the new height (unlike on Android devices where it behaves as expected). Oddly enough, if you rotate back to the original orientation, the image does resize but for the previous orientation - so now it's incorrect!

Interestingly, I've noticed that interacting with another element on the page that renders based on screen height while the incorrect image is displayed actually corrects the image size issue.

At this point, I'm considering forcing a CSS reload upon orientation change, unless there is a better solution at hand. Would this require implementing something in JavaScript, or is there a way to achieve this purely through CSS?

Here's the relevant CSS snippet:

    position: relative;
    height: 90vh;
    z-index: -3;
    bottom: 50px;
    background-size: auto 100%;
    background-position: 30%;
    background-repeat: no-repeat;
    background-image:image-url("the/path/to/my/image.jpg");

*Note: jQuery is not an option here, as this is an AngularJS application

Answer №1

It seems like you're unsure about what exactly you need, but have you considered using a CSS media query to differentiate between portrait and landscape orientations? By implementing this, you may be able to achieve more precise backgrounds when the screen orientation changes.

@media only screen and (orientation: landscape) {
  background-size: auto 100%;
}
@media only screen and (orientation: portrait) {
  background-size: 100% auto;
}

However, without more specific information about your problem, it's difficult for me to provide a definitive answer. Nevertheless, this suggestion could potentially guide you in the right direction.

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 there a way to drop a pin on the Google Maps app?

Is there a way to pinpoint the specific location on Google Maps? <google-map id="map-container" width="100%" height="100%" class="maps"></google-map> ...

I'm having trouble getting the footer to stay at the bottom of my website

Struggling with positioning my footer at the bottom of my website, I've tried various solutions posted by others but they don't seem to work for me. I've experimented with different methods like using 'Bottom: 0;' or placing my fo ...

Struggling to align block elements correctly after changing them to inline

I've been trying to align this paragraph while keeping the navigation menu and logo in their correct positions. I attempted to make everything inline, but that didn't work. Then I experimented with the float property, which only made things worse ...

style the table cells based on results of winner values retrieved from JSON

After fetching JSON data, I am utilizing angular JS to present it in a table. The table consists of multiple rows that are populated from the JSON file using ng-repeat. The value for Status.winner can either be 0 or 1. If the winner's value for a p ...

Issue with Font Awesome 5 icons not displaying properly after integrating Bootstrap

Trying to spruce up my buttons by adding some fontawesome icons from bootstrap. The icons I'm using are: fas fa-user fas fa-users They display fine without any styling. However, when I apply the bootstrap button css, the "fa-users" icon appears as ...

angular-routing does not seem to redirect properly

I'm encountering an issue after logging in, as my page is not redirecting to the main page. Upon investigation, I found that the login condition works when using $window.location. However, I want to implement angular-route to restrict access to the ma ...

Tips for customizing the appearance of a label when a MUI Radio Button is selected

Hello everyone, I am attempting to customize the label text color of a radio button to turn blue when selected. https://i.stack.imgur.com/btSc2.jpg HERE IS THE CODE FOR MY MUI BUTTON SO FAR import * as React from "react"; import Radio from &quo ...

Styling Challenges with CSS/AngularJS Accordion in Footer

I want to create a page layout as shown below: +---------------------------+ | Auto-fill / v scrollable ^| | || | || | v| +---------------------------+ | Fixed [][][] ...

Scrollbar Excess in Windows 10 on Chrome Version 76

<div style="overflow-x: hidden"> <div style="height: 100%"> <p style="margin-bottom: 1rem"> lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan nisl id maximus gravida. </p> ...

Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page. app.controller('thingCtrl', function ($scope, $rootScope, $routeParams ...

Can you provide the Angular JS alternative for executing a POST request similar to this Curl command?

Trying to translate a Curl command into Angular JS code has been a challenge for me as a newcomer to AngularJS. This specific instance involves a mobile app built on the ionic framework, which utilizes Angular JS. The original curl command looks like this ...

What might be causing the in-viewport javascript to not work in my code?

Why is my in-viewport JavaScript code not functioning properly? Link to JSFiddle code When the Click to move button is clicked, the cat image will slide correctly. However, when implementing the following code: if($("#testtest").is(":in-viewport")) ...

Adjust the width of the dropdown menu in Twitter Bootstrap's typeahead feature depending on the search

Not entirely certain if this issue is related to jQuery, but there's a strong suspicion that it might be. The problem at hand can best be described by the picture provided: The query output exceeds the width and doesn't resize or scale according ...

Curious about how to swap the positions of these two divs?

After wrapping them in divs and adding inline-block to both elements to display them side by side, I'm now exploring options to switch their positions. Specifically, I'd like the right element to be on the left. Any ideas on how to achieve this? ...

Is there a way to activate the device back button within the Ionic framework?

I disabled the back button under certain conditions by registering an action event like this: $ionicPlatform.registerBackButtonAction(function (event) { if (condition) { event.preventDefault(); $ionicHistory.nextViewOptions({ ...

Dealing with the output from the response.write() function in Express within an Angular $http request

Currently, I am attempting to upload a CSV file using the ng-file-upload library. Below is a snippet of my code: Upload.upload({ url: baseUrl + '/file-upload', data: { file: file } }) .then(function(res) { console.log(' ...

Is one-way data binding possible in Angular?

I'm inquiring about one-way data binding with AngularJS. Imagine we have two input boxes on the same page, labeled A and B. Is it possible for input A to change input B, without input B affecting input A? I am aware of Angular's bindonce featu ...

Which takes longer to render: individually drawn images placed via absolute positioning, or one complete image?

I currently have a collection of "cards" on my website that are jpg images, but I am considering switching to an HTML/CSS solution. This change would involve placing numerous small icons on a background and adding stylish text on top. My concern is determ ...

Tips for delivering a variable to a React Native Stylesheet

Is there a way to pass a variable to the "shadowColor" property in my stylesheet from an array declared in the code above? I keep encountering a "Can't find name" error. Attempting to use a template literal has not resolved the issue. Any assistance w ...

Poorly positioned text displayed inline in HTML

My attempt to place a title in a div toolbar next to some images has hit a snag. The text is not aligning correctly; it should be positioned at the top of the toolbar, but it stubbornly remains at the bottom without budging. I wish for it to be vertically ...