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

Choose a child using react material ui's makeStyles

Currently utilizing React and Material UI, I am attempting to use the nth-child selector with the MUI makeStyle function. However, it is not working as expected. Here are some screenshots for reference: https://i.sstatic.net/5dVhV.png https://i.sstatic.ne ...

Utilize Bootstrap to switch between 'collapse' and 'collapse in' depending on the device being used

I have a collapsible panel set to default "expand" (collapse in) and it is working well. However, I would like to make it "collapse" (shrink) for mobile and tablet devices. Is there any built-in feature in Bootstrap that can help me achieve this? <div ...

Arranging icons at the bottom of the post with a text box that changes dynamically

My challenge is that when the content in a box overflows, the box size increases and pushes the icons out of place. I want to ensure that the icons remain in a fixed position. This is how it currently looks: The comment, delete, and likes count end up on ...

Creating a fading effect on an image in relation to another dynamic image

I am currently facing an issue in my code where I am trying to make one image fade in next to another, regardless of the position of the movable image on the screen. The movable image can be controlled using arrow keys, and when I move it across the screen ...

Combining an image and a card in Bootstrap 5: a step-by-step guide

Is there a way I can align an image and a card in the same line like in this example? I want the image and card to be combined in one line, but when the page is viewed on mobile devices such as Android or iOS, I want the image to appear at the top with th ...

Tips for locating all "a" tags within an angular $http request

(Angular) I am facing an issue with locating all "a" tags displayed within the data-ng-bind-html="post.content" in my Angular http request. Previously, I had a jQuery function that found all links, extracted the URL, and added an onclick function to open t ...

accomplishing validation in Angular forms while avoiding the use of the HTML form tag

I'm looking to implement Angular Form Validation without the use of an HTML form. I attempted the following code, but unfortunately, the button remains enabled. <ng-form name="login"> <div class="input-group"> <span class="input ...

Is there a way to efficiently create an ng-repeat for multiple divs?

I am looking to iterate through a collection of divs, as mentioned below. Each object in the list will have content-data and a link to an image. The code provided shows individual entries for each list item, but I would like to retrieve it from the angular ...

Utilizing Material UI Grid spacing in ReactJS

I'm encountering an issue with Material UI grid. Whenever I increase the spacing above 0, the Grid does not fit the screen properly and a bottom slider is visible, allowing me to move the page horizontally slightly. Here is the simplified code snippe ...

Can AngularJS effectively handle both routing and sorting functions at the same time?

When setting up table sorting in my app, I used a helpful tutorial as a guide and it worked perfectly. In order to make my column headers clickable for sorting, I structured them like this: <td> <a href="#" ng-click="sortType = 'name' ...

Dedicated pages for individual items within a MEAN application

I'm currently developing an application using Node, Express, Mongoose, and Angular. I have successfully displayed all items on a single page. My next task is to create a separate page for each item from the database. To achieve this, I set up a route: ...

AngularJS - Setting an initial delay for ng-bind

We have a span element with the following attributes: <span role="link" ng-show="showLink()" ng-bind="textLink"></span> (Just an fyi: we implemented a fade-in, fade-out animation for this link, hence the use of ng-show instead of ng-if) The ...

Acquiring an Array from AngularJS with Laravel Controller

Just starting out in Laravel and Angularjs, I'm attempting to pass an array from Angularjs to a Laravel controller. While I'm not encountering any errors, I am struggling to retrieve the data in the Laravel controller and use it effectively. Here ...

Issue with white spaces in footer content in Chrome browser

Currently in the process of developing a website and encountering a strange bug that only seems to be affecting Chrome. Despite having the latest version of Chrome, it appears to be an issue that was prevalent in older versions (v18 - v20). The problem is ...

Validating Angular UI Route state with Protractor

I've been experimenting with the protractor framework to conduct tests on my angular application. Is it possible for me to verify the angular state during an end-to-end test? ...

How do I set up a navigation bar item to align to either side based on the selected language?

I need to adjust the positioning of the last list item component within a specific div. The webpage is available in both Arabic and English, with the direction changing based on the selected language. Here is a snippet of CSS code that I'm using: #na ...

Leveraging ngsanitize alongside cascading style sheets

https://i.stack.imgur.com/o0rgS.png When utilizing ngsanitize, only the HTML is displayed without any applied CSS. For instance: The provided image is expected as output, but using ngsanitize results in only the text being visible. What additional steps ...

Issue observed with the functionality of checkAll and uncheckAll after a user interacts with a single checkbox

After completing an Angular course on Udemy, I decided to implement a custom checkbox in my Angular app. However, I encountered an issue where the UI was not updating properly when using checkAll and uncheckAll functions after the user interacted with an i ...

AngularJs service Sinon stub is failing to function as anticipated

I am currently utilizing Karma, Jasmine, and Sinon for testing an AngularJs application. In a controller, a service is injected, and I aim to utilize the Sinon sandbox to stub a method on the service. Below is the controller code: (function () { &apos ...

Manipulating the location where a dropdown menu intersects with a button

Is there a way to adjust the drop-down menu positioning so that it aligns with the button on the top right side of the menu pop-up, rather than the top left as it currently does? Below is the code I have borrowed from an example on W3Schools. .dropbtn ...