Maintaining alignment of background elements and div images

I'm struggling to align images properly across different devices. It's more challenging than I anticipated.

Currently, on mobile in portrait mode, the image is not displaying as I want it to. Ideally, I want it to be closer to how it looks in landscape mode.

I've experimented with:

- object-fit: cover - object-fit: none

But I haven't had any success with these options. Should I wrap all the divs in a container first?

html {
    background: url('https://cdn.glitch.com/87ed8b1a-63dd-4b25-a90a-376a6af4b751%2Fbackground3.png?1547124819891') no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    font-family: sans-serif;
    font-size: 16px;
}

/* ----- Structural Styles ----- */
 

.header {
    overflow: auto;
}

#header p{
    opacity: 255;
}


.hands {
  height: auto;
  width: auto;
  position: absolute;
  bottom: 0px;
  right: 0px;
  object-fit: none;
}

.container {
  
  justify-content: center;
    position: fixed;
    bottom: 80px;
    left: 38%;
    right: 33%;
}
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8>

    <title>untitled</title>
    <meta name="author" content="">
    <meta name="description" content="">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="style.css">
</head>


<body>
  <div class="hands">
  <img src="https://cdn.glitch.com/87ed8b1a-63dd-4b25-a90a-376a6af4b751%2FHands_paper3.png?1547124446277">
 
    <div class="container">
        
        <div class="header">
            <a id="myBtn" style="float: right;font-size: 1.5em;">&#9776; </a>
        </div>
        
        <div id="story"></div>
        
        <div id="myModal" class="modal">
            <!-- Modal content -->
            <div class="modal-content">
                <span class="close">&times;</span>
                <h1>Paused</h1>
                <p>Put information about your game here</p>
            </div>
        </div>
    
    </div>

    <script src="modal.js"></script>
    <script src="settings.js"></script>
    <script src="ink.js"></script>
    <script src="Brexit-Snatch.js"></script>
    <script src="main.js"></script>
  </div>
</body>

</html>

Answer №1

Make sure to add width:100% to the hand image to achieve the desired look. Thank you!

html {
    
}

body{
background: url('https://cdn.glitch.com/87ed8b1a-63dd-4b25-a90a-376a6af4b751%2Fbackground3.png?1547124819891') no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    font-family: sans-serif;
    font-size: 16px;}
 

.header {
    overflow: auto;
}

#header p{
    opacity: 255;
}


.hands {
  height: auto;
  width: auto;
  position: absolute;
  bottom: 0px;
  right: 0px;
  object-fit: none;
}

.hands img{
width:100%}

.container {
  
  justify-content: center;
    position: fixed;
    bottom: 80px;
    left: 38%;
    right: 33%;
}
  <div class="hands">
  <img src="https://cdn.glitch.com/87ed8b1a-63dd-4b25-a90a-376a6af4b751%2FHands_paper3.png?1547124446277">
 
    <div class="container">
        
        <div class="header">
            <a id="myBtn" style="float: right;font-size: 1.5em;">&#9776; </a>
        </div>
        
        <div id="story"></div>
        
        <div id="myModal" class="modal">
            <!-- Modal content -->
            <div class="modal-content">
                <span class="close">&times;</span>
                <h1>Paused</h1>
                <p>Put information about your game here</p>
            </div>
        </div>
    
    </div>

   

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

Looking for a rival on socket.io

Currently, I am working on a script utilizing socket.io with express in node.js to find an opponent. In this setup, only two players are allowed in a room. If no free rooms are available, a new one should be created automatically. The core logic of the c ...

Extracting text from HTML tags can be quite tricky, especially when you need the text within a specific tag like <td> but not within any nested tags like <

Is there a way to extract only the numbers from the <td> tag and ignore any text within the <strong> tag that is nested inside it? I am currently using selenium code but it returns the entire content of the <td> tag. Python Code: wait. ...

How can I prevent Javascript click events from cascading, or ensure proper assignment to multiple divs in my code?

My goal is to create a single-page website where different sections are revealed or hidden based on navigation button clicks. However, I'm encountering issues with certain buttons not working unless the first button is clicked. Additionally, there&apo ...

Aligning the title vertically in Ionic on Android device

Currently, I am in the process of developing an application using the Ionic framework and cordova. After uploading my app for testing purposes, I encountered a small issue. The title in the top bar on Android appears to be misaligned vertically. Is there a ...

What is the method for achieving the equivalent effect of "background-size: cover" on an <img>?

I am looking to ensure that an <img> has the smallest possible size without any empty spaces inside a div, while also being perfectly centered both horizontally and vertically. The image size may vary. To better illustrate, here is an example: http: ...

Looking for a specific search term within the middle of strings in an array

Is there a way to improve the autocomplete feature of my input field so that it shows suggestions based on any part of the word typed in? I currently have it set up to only show suggestions if the input matches the start of a word in the array. How can I m ...

The Impreza theme is experiencing difficulty displaying Font Awesome icons

Recently, I had a client who needed a WordPress website. After working on the project on my own server, I finally completed it and transferred the entire site to the client's main domain at gulugalmarketing.com. Everything was functioning perfectly o ...

Adding a Library to Your Project

Being a newcomer to importing libraries into personal projects, I am attempting to import the mathjs library package for the first time. (). However, I am running into the issue on my website where it says "math is undefined" when I try to use it. You c ...

Preventing Scope Problems in AngularJS

Spending more than 4 hours trying to figure out why my ng-model directive was not correctly binding with ng-options within my controller was frustrating. The <select> element seemed to be initialized properly, receiving a value from the parent scope, ...

Discord.js: Merging strings while pushing to an array

I am currently updating an embed message to notify users who have "enlisted" in a list by reacting. However, I am encountering an issue where the strings from the entire array are getting combined when the length of the array reaches 2 before adding a new ...

Unable to properly utilize environment variables on Vercel when using Nuxt framework

I'm encountering difficulties accessing my environment variables on Vercel. When I test the site on my localhost, everything works fine; however, once it's deployed to Vercel, the access to environment variables in my components and plugins direc ...

Adding a div via an Ajax call is only successful during the initial page load

Currently, I am utilizing a combination of YQL and jQuery to retrieve content from a distant page. While I am able to successfully load the content during the initial page load, I encounter an issue when attempting to return to the same page after navigati ...

What is the process for obtaining the eTag (MetaData) from a DocumentInfoRecord retrieval in SAP Cloud SDK using Javascript?

I am utilizing the SAP Cloud SDK for javascript to manage DocumentInfoRecords. Upon updating a DIR, I encountered error 428. Therefore, I require the etag of the request similar to what is available in the SAP Cloud API. How can I retrieve the etag from t ...

Tips for effectively utilizing the mock-ajax library in conjunction with Jasmine

Currently, I have a function that requests JSON data and then modifies the DOM in the success function. To simplify my Jasmine tests, I am attempting to utilize the mock-ajax library instead of exposing private functions for mocking. Despite setting reque ...

Is it possible to have text centered only on desktop devices and left-aligned on mobile devices using Bootstrap 4?

I have the following code for the header where I want two pictures to be at either end, preferably at the corners. The text should be directly in the center on a desktop, and on mobile, all images and text should be stacked. Is that possible? To view the ...

Populate a secondary dropdown menu using the selection from a primary dropdown menu and retrieve the corresponding "value" instead of displaying the value as a dropdown option

I am attempting to create two dropdowns that are populated by another dropdown. Below is the code: HTML: <form type=get action="action.php"> <select name="meal" id="meal" onChange="changecat(this.value);"> <option value="" disabled select ...

Restrict the number of dynamic form elements to a maximum of 10 entries

I am working on a feature where users can refer their friends and the data will be saved in a database. <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type='text/javascript' sr ...

Is there a way to adjust the height of one div based on the height of another div in Bootstrap?

I am experimenting with a Bootstrap example featuring a table in the left column and 4 columns in 2 rows in the right column. Check out the code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css ...

Ways to implement pseudo classes to display title text upon button click

Is it possible for the user to input their name and have it appear on the screen once they click the save button? I am using Mantine design framework and want to utilize pseudo classes. However, styling two classes at once seems tricky in Mantine compared ...

Issue: The DLL initialization routine failed for electron, but it works perfectly fine on node.js

Currently, I am facing an issue while attempting to load a custom module in electron that is written in D using the node_dlang package. The module loads successfully with node, but encounters failures within electron. The test run with node, which works w ...