Two divs are overlapping when the screen size is decreased

Here is a basic HTML webpage that has responsive design, with the exception of one div (goplay) that overlaps other elements on the page when the screen size is reduced instead of moving below the image.

This webpage uses an external stylesheet for styling.

 #wrapperlp {
        width: 100%;
        margin: auto;

    }

    @media screen and (max-width: 800px) {
        #wrapperlp {
            width: 90%;
            min-width: 100px;
        }
    }

    #headerlp {
        font-size: 30px;
        color: white;
        text-align: center;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    #para {
        font-size: 20px;
        color: white;
        text-align: center;
    }

    #game_img {
        height: 250px;
        width: auto;
        margin-bottom: -30px;
        position: relative;
        display: inline-block;
        float: left;
        margin-top:-30px;
        padding-top: 5px;
        max-width: 100%;
    }

    #goplay {
        position: relative;
        display: inline-block;
        float: right;
    margin-top:-250px;
        margin-left:80px
    }
    #spacer {            
        height: 40px;           
        margin-left: auto;
        margin-right: auto;
    width: 100%;
    max-width: 900px;
    padding-top:20px;
    }

The following HTML code references the above CSS:

<div id="wrapperlp">
<div style="background-image: url(https://.jpg); height: 430px; width: 1000px; margin-left: auto; margin-right: auto; max-width: 100%;">
<div id="headerlp">Some Text</div>
<div id="para">More Text</div>
<div id="game_img"><a href="//www.youtube.com/" target="_blank"><br />
                <img src="https://.png" height="auto"/></a></div>
</div>
</div>
<div id="goplay">----form----/div>
<div id="spacer">
<div style="position: relative; float: left">Text</div>
</div>

Answer №1

It is recommended to use percentages for margin-top and left values instead of pixels to avoid overlay issues.

Answer №2

It appears that there are a few missing divs in your code. The closing tag for the goplay div seems to be incomplete, as it's not functioning properly. Additionally, the bottom spacer appears to be lacking a proper closing tag as well. It's unclear if it should encompass any content.

Could these errors be due to copying and pasting?

Typically, using negative margins can override other divs. In general, it is advisable to avoid using negative margins whenever possible.

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

What is the best way to add flair to the HTML <title> tag?

Just a quick question - I'm wondering if there is a method to apply CSS styles to an HTML element. Here's an example declaration: title { color: red; font-family: 'Roboto', sans-serif; } ...

CSS unexpectedly transitions away

Check out this link for additional details As the cursor moves away from the element, it swiftly reverts back to its original form (I've demonstrated this in the video) .productinfo { display: flex; flex-direction: column; align-items: c ...

What is the optimal event to trigger a function when there is any modification in a text area using Javascript?

I need a function to trigger every time there is any modification in my textarea, such as characters being typed, deleted, cut, pasted, etc. Currently, I am using: onkeyup || onmousemove = function(); It appears that only onmousemove is being triggered. ...

Can v-model be used with dynamic object keys?

I would like to showcase my data structure as follows: form: { email: '', password: '' } My goal now is to implement a loop to dynamically set the model using the form object. <div class="my-1" v-for="(value,name, index) in ...

Is IntelliJ equipped with CSS autocomplete and Emmet features?

Encountering some challenges with IntelliJ 13 and autocompletion while working on CSS. Previously, to set margin: I would simply type: mar then press Tab. However, in the new version, it now shows max-resolution instead: Initially thought it might be rel ...

Strange behavior noticed with Bootstrap accordion

The current behavior of the product specs section is as expected. Clicking on group 1 shows its content, and when clicking on group 2, it minimizes group 1 and displays group 2. However, the issue arises with the next two categories, Usage and Installatio ...

What is the best way to align the Burger menu with the logo on the same row and have the menu dropdown open below the header?

Is there a way to align the Burger menu with the logo and have the menu dropdown open below the header? I attempted to position the burger menu next to the logo, but it didn't turn out the way I thought it would. Coding in html and css is still new t ...

I am a newcomer to HTML and I am eager to display the selected options from a <select> element

Can someone help me display the selected licorice flavor, chocolate color, and topping? For example: "Green apple, white, christmas sprinkles." I'm not sure if assigning a numeric value to each option is necessary. I did it on a whim. Please suggest ...

What is the best way to loop through an array of JSON data in order to consistently retrieve the initial JSON object?

How can I retrieve only the full highlight videos from the JSON object in the video array? { "response": [ { title: "United vd Chelsea", "videos": [ { "title": "Highlights&quo ...

Decrease the gap between Bootstrap horizontal form elements

Looking to enhance the visual appeal of my form controls, I am using Bootstrap 4 horizontal form to eliminate unnecessary spacing and create a more compact layout. Though I have applied the CSS snippet below to reduce spacing, there is still a noticeable g ...

Changing the Div heights in Material UI with grid layout customization

I have a project that requires me to implement material-ui. Is there a way I can adjust the width and height of the div containing the "Sign In With" text (as shown in the first image) to bring the buttons closer to the text? Transformation from this: ht ...

Retrieve the value of a JavaScript variable within an HTML or EJS document

My JavaScript file, named main.js, contains a JSON object like the following: const person = {}; person.AGE = '17'; person.GENDER = 'Male'; To load this file in my .ejs file, I use the following code: <script type="text/javascript ...

What could be causing checked="checked" to fail validation in JavaScript?

I'm feeling a bit puzzled about this issue. Here's the HTML code I have - <input type="radio" id="20577091" name="q_engine" value="20577091" style="position: absolute; opacity:0;" checked="checked" /> and here is the corresponding JavaScr ...

Convert the JSX element to a string using the necessary function in React

Currently, I am utilizing React big calendar and facing an issue where the tooltipAccessor requires a string input. However, I need to include additional data in the tooltip while maintaining UI formatting (as shown in the image). Is there a way to pass J ...

I had hoped for the search results to be displayed in neat columns, but unfortunately only the text is formatted that

I am working on a WordPress plugin that displays search results. Here is the PHP code for the results: <?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link http://w ...

Tips on optimizing a setTimeout script for seamless integration with an HTML form

Here is the script: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> function addToCart() { document.getElementById("msgs-box").innerHTML = "Item added to cart s ...

The HTML upload failed due to various errors, preventing the page from loading properly

There seems to be an issue with the functionality of page "bookUpdate.html" due to some errors. I can access this page by clicking on the "Edit" button from the page "bookList.html". Bootstrap works fine on all other pages except for this one. I attempted ...

Add the div element to a different div in the HTML code

I'm struggling with my HTML layout. I have a <div> ... </div> section positioned in a fixed location. My goal is to be able to use that <div></div> multiple times within the body tag. I attempted various methods using jQuery a ...

Is it possible to evaluate the complexity of automating the user interface of a web application?

What are some common indicators of the challenges involved in automating the frontend of a web application? One example could be ensuring that all “critical” elements have stable ID attributes that do not change frequently. Are there any other similar ...

Modify the background color of an R chunk in a bookdown gitbook

Is there a method to eliminate the grey background color in order to display the colorful class? https://i.sstatic.net/l1Hhi.png https://i.sstatic.net/4aHMF.png ...