Background image stretching causing layout problems on mobile devices

I've run into an issue where my website looks perfect on a desktop browser, but when viewed on a mobile device, the background image messes up everything and the responsiveness is not achieved.

If you'd like to see the site in question, you can visit:

Below is the code I used for setting the background image in the body using CSS:

body {
    /* Location of the image */
    background-image: url('../img/image.jpg');

    /* Background image is centered vertically and horizontally at all times */
    background-position: center center;

    /* Background image doesn't tile */
    background-repeat: no-repeat;

     /* Background image is fixed in the viewport so that it doesn't move when 
        the content's height is greater than the image's height */
    background-attachment: fixed;

    /* This line ensures the background image rescales based on the container's size */
    background-size: cover;

    /* Set a background color that will be displayed while the background image is loading */
    background-color: #464646;

    background-color:#FFF;
    font-family: 'Montserrat', sans-serif;
    color: #3E404B;
}

The website appears fine on a desktop and adjusts well when resizing the page. However, there seems to be an issue with how it appears on mobile devices:

Here's how it looks on mobile:

Do you think the parallax code could be causing this issue?

body,
html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

p {
    margin: 0;
    padding: 10px 5%;
}

.slide {
    box-sizing: border-box;
    height: auto;
    min-height: 100%;
    min-width: 100%;
    background-size: cover;
    box-shadow: inset 0 10px 10px rgba(0,0,0,.3);
}

I would greatly appreciate any help or suggestions. Thank you!

Answer №1

@media screen 
  and (device-width: 320px) 
  and (device-height: 640px) 
  and (orientation: portrait) {
body { width: 100%; max-width: 100%; height: auto;
 }
}

Alternatively, you could assign a class to your image in the HTML file and apply the .test class with the same media query, ensuring the dimensions are set accordingly with (orientation: landscape).

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

Design featuring a fixed top row and a scrollable bottom row

I need to divide a div container into two vertical sections, one occupying 60% of the space and the other 40%. The top div (60%) should always be visible, while the bottom div (40%) should be scrollable if it exceeds its limit. I have tried different app ...

What is the proper way to link an image in a nuxt project?

I am working on a modal in the app.html file of my Nuxt project that prompts Internet Explorer users to switch to another browser. The modal includes links to three different browsers for download. Although the modal is displaying correctly, I keep encount ...

Using htaccess to eliminate PHP and HTML files from your website

I've been scouring the Internet for quite some time now, trying to find a working htaccess file for my website. I'm using CuteNews, a news CMS that offers URL rewrite functionality. However, when I enable URL rewriting, it causes my news pages to ...

Is it possible to isolate specific HTML elements within a designated area?

Is it possible to identify which elements are located within a specific rectangular region on a web page identified by a URL? UPDATE: The default settings for screen resolution, font size, etc. can all be adjusted to reasonable values. ...

Maintain the text layout when copying and pasting from the Angular Application

After noticing that copying and pasting text from an Angular Application to a text editor like Microsoft Word results in losing the original format, I decided to investigate further. An example I used was the angular material website: https://material.ang ...

Initiate the preloader function with a GIF loading image to display while my PHP script processes and retrieves data

This PHP file is responsible for downloading image and data files from the server. <?php header("Cache-Control: no-cache, must-revalidate"); //header("Expires: Tue, 25 sep 2012 09:00:00 GMT+5.30"); header("Content-Type: applica ...

What are some ways I can troubleshoot my contact form?

As someone new to web design, I recently completed my very first site using a combination of HTML, CSS, and a touch of JavaScript. I managed to create a small contact form within the site, but now I'm wondering if there's a way to make it functio ...

Internet Explorer 10 is experiencing issues with attribute binding when it comes to click events

I'm currently working on an application and I'm experiencing some issues with IE 10. The captcha text displays correctly the first time, but when I try to refresh it by clicking the button, it doesn't seem to work. My guess is that there&apo ...

Verify the HTML embed code with either PHP, JavaScript, or the Zend PHP framework

I have a quick question: Are there any effective methods for validating an HTML embed code? I am currently using Zend Framework and prototype+scriptaculous and would appreciate any hints or tips related to this environment. Thank you! ^^ ...

Creating an organized layout with multiple bootstrap toasts in a grid formation

Is there a way to create multiple Bootstrap Toast elements side-by-side and top-to-top? For more information, visit: https://getbootstrap.com/docs/4.2/components/toasts/ <div aria-live="polite" aria-atomic="true" style="position: relative; min-height: ...

Deleting items with a swipe gesture in Angular 10

Hey there, fellow developer! I could really use some assistance in implementing the swipe delete feature for our Angular project. Could you take a look at the screenshot provided below? https://i.sstatic.net/LqXlm.jpg The code snippet given to me for thi ...

What is the method to retrieve the class name of an element when the div is created as '<div id 'one' class="element one"></div>'?

I have three elements named one, two, and three, declared as seen below: <div id =container> <div id 'one' class="element one"></div> <div id 'two' class="element two"></div> < ...

Tips for incorporating razor isolated/code behind CSS classes into MudBlazor components

Within my codebehind file, I have defined a CSS class. When I use the "class" attribute on normal HTML elements, the style is applied correctly. However, if I apply the class to a MudElement using the "Class" attribute, the style does not get pulled. Altho ...

Validation using AngularJS and HTML5

My form includes the use of the required tag on inputs, which works correctly. However, I have a ng-click="visible = false" property on the submit button that hides the form when data is submitted. How can I ensure that this property is only set to false i ...

The hovering of the mouse over a dropdown menu causes a division on the page to shift

Creating a website with a dropdown menu and slider division can be tricky. When hovering over the menu, the submenu displays but causes the slider division to shift down. Does anyone have suggestions on how to fix this issue? Below is the code: <html& ...

Automating the extraction of dynamic tables using Python and Selenium from nested classes

I've been attempting to extract data from two tables that are updated every 0.5 seconds, with the tables nested within a class structure. I initially used Selenium's driver.find_element_by_xpath and attempted to retrieve the data using a series o ...

Tips for displaying a hidden div even without JavaScript enabled

I have a scenario where I am using display:none to hide a div, and this div is supposed to be shown only when the user clicks on the + icon. However, I also want to ensure that if JavaScript is disabled, the div is shown by default. How can I achieve this? ...

Adjusting the size of background images using media queries to scale down accordingly with the size of the browser window while

Currently, I am working on a website project where I am using a background image with Bootstrap 4. However, I am facing an issue where the image does not center properly as it resizes at different breakpoints. I am contemplating whether to use resized im ...

What is the best way to load ajax content after a specific element in jQuery?

Here is the HTML code I am working with: <div id="mydiv"> </div> I want to use jQuery to load content after my DIV element. This is what I have tried so far: $("#mydiv").load("/path/to/content.html"); However, this code produces the follow ...

Troubleshooting mat-accordion title problem on mobile devices

Despite reading numerous blogs and conducting extensive searches on Google, I am still unable to resolve the CSS issue related to Angular material below. Your assistance in fixing this problem would be greatly appreciated. Desktop view: https://i.stack.im ...