What is the best way to prevent 2 divs from overlapping on a webpage?

I'm having trouble getting the smaller div to display right below the larger red div. I tried using the display block css property, but it doesn't seem to be working as expected.

Unfortunately, I can't provide an image here, but you can view it through this link:

Below is the HTML code snippet:

<!DOCTYPE html>
<html>
    <head>
        <title>Select Ye Favorite</title>
        <link rel='stylesheet' type='text/css' href='css/list.css'/>
        <link rel="stylesheet" type="text/css" href="jquery.imgareaselect-0.9.10/css/imgareaselect-default.css" />
        <!-- Remaining script imports are here -->
    </head>
    <body>
        <div id='header'><h1 id='titleSite'>List Life</h1></div>
        <div id='list'></div>
    </body>
</html>

And here is the CSS code snippet:

![html, body
{
    height: 100%;
}
/*
* {
    border: 2px solid black;
}*/
#header{
   /* z-index:1;
    border-radius:5px;
    background-color:#ECF7C6;
    height:60px;
    position:fixed;
    margin-top:-20px;*/
    z-index: 0;
    position: fixed;
    width: 98.75%;
    margin-top: -2%;
    margin-bottom:0.5%;
    margin-left:0.25%;
    margin-right:0.25%;
    height: 100px;

    border: 2px dashed black;
    background-color:#FC3F4D;
    border-radius:5px;
}
div{height: 50px;
    width: 100px;
    border: 2px solid black;
    border-radius: 5px;
    margin:auto;
    display:block;
    position:relative;

}
div  #titleSite{
    position:relative;
    top:10%;
    color:white;
    text-align:center;
    font-family:Arial,sans-serif;
    font-weight:bold;
    border: 2px dashed white;
}][2]

Answer №1

give this a shot:

#siteTitle{
    position:absolute;
    top:15%;
    color:black;
    text-align:center;
    font-family:Verdana,sans-serif;
    font-weight:bold;
    border: 3px solid black;
}
#list{ position:relative; top:100px;}

Answer №2

The reason for this occurrence is due to the position:fixed setting on your #header. If you prefer not to modify this, simply include the following CSS code:

#header{
  top:0px;
}
#list{ 
    margin-top:100px; /* Adjust as needed (height of your header + gap between both divs) */
}

Answer №3

Your CSS styles are a bit unclear, making it difficult to discern your intention. The root of the problem lies in the header div being set with a position of fixed. Fixed-positioned elements are taken out of the normal document flow and positioned relative to the browser window, causing the list div to be displaced because it doesn't consider the header div.

To resolve this issue, simply remove the following CSS declaration...

position: fixed;

from the header div.

Answer №4

Creating a Website

<div id='header'><h1 id='titleSite'>Adventure Finder</h1></div>
<div id='adventures'></div>

CSS Styling

To style the adventures list, use the following CSS:

#adventures{ 
    margin-top:80px;
}

If you want to keep your #header fixed in position, do not change its position property.

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

Adjust the size of the text and save it in a cookie for later use

I am in need of a script that can dynamically increase and decrease the font size on a website while retaining the user's chosen setting even after they return to the site. I believe utilizing cookies is the way to achieve this functionality. Despite ...

When using React, the page loads and triggers all onClick events simultaneously, but when clicking on a button, no action is taken

I have a strong foundation in HTML and CSS/SASS but I'm just getting started with React. Recently, I encountered an issue that has me stumped. I am trying to highlight a button on the navigation bar based on the current page the user is on. I attemp ...

Retrieve data from an ASP.NET Web API endpoint utilizing AngularJS for seamless file extraction

In my project using Angular JS, I have an anchor tag (<a>) that triggers an HTTP request to a WebAPI method. This method returns a file. Now, my goal is to ensure that the file is downloaded to the user's device once the request is successful. ...

Steps for transferring data between two components

I'm looking for a way to transfer an object's id from one component to another. <ng-container matColumnDef="actions"> <mat-header-cell *matHeaderCellDef></mat-header-cell> <mat-cell *matCellDef="let user"> ...

What is causing the colored SVG to appear lighter than the intended color after using a mask to recolor it?

I have a project using VueJS where I am trying to change the color of SVGs by looping through them and using mask and rect tags. However, I am noticing that as the icon index increases, the color of the icon becomes lighter. What could be causing this issu ...

What is the best way to set the width of an inner element as a percentage of the Body's width?

Applying a percentage width to any inner element of a page will typically result in that element taking a percentage of its parent container's width. Is there a way to specify the width of an inner element as a percentage of the overall Body width, r ...

The ng-repeat function is unable to fetch data from a JSON file

Within my AngularJS framework template, I have the following snippet of html code: <ul class="sb-parentlist"> <h1 class={{headerClass}}> Popular</h1><div data-ng-repeat="data in data track by $index"> <li> ...

triangle as a backdrop

Looking for a unique design for your website background? How about a triangle split with black on one side and white on the other, like this image? I can't seem to find this online, so any help would be greatly appreciated. Is it possible to achieve t ...

Save this text in HTML format to the clipboard without including any styling

When using this code to copy a htmlLink to the clipboard: htmlLink = "<a href='#'>link</a>"; var copyDiv = document.createElement('div'); copyDiv.contentEditable = true; document.body.appendChild(copyDiv); ...

Eradicate white space in a JavaScript code

Calling all JS programmers! Here's a challenge for you, check out this demo: https://codepen.io/gschier/pen/jkivt I'm looking to tweak 'The pen is simple.' to be 'The pen issimple.' by removing the extra space after 'is& ...

Code Snippet: Adjust Table Column Alignment using CSS

Apologies for the basic question, as I am new to CSS. Below is the UI that I am working with: https://i.stack.imgur.com/crAYE.png Here is the code that corresponds to the UI: <div class="row centered-form center-block"> <div cla ...

What is the best way to horizontally align an image beneath a navigation menu that is built using <ul> tags?

Seeking a way to center an arrow graphic under the selected item in a simple CSS drop-down menu? Considering using the :after selector, but currently being used for drawing dividing lines between menu options: HTML: <ul> <li>Option Zero&l ...

Fetching the added information using ajax

Hey everyone, I have a question about reloading the appended data on my page. The page has infinite scrolling functionality and I want to reload the elements that are added when a particular element is clicked. The loading works fine for elements that were ...

Aligning text and checkboxes for perfection

Looking for a solution to align text and checkbox without using a blank image; I have the following HTML code: <span><b>System Type</b></span> <img src="~/Content/images/blank_img.png" alt=" ...

Various Plus/Minus Containers

One issue I am facing is that when using multiple counters on the same page, my - and + buttons to decrease or increase the number in a text box do not function properly. The script provided below works for one counter. How can I modify this code so that ...

Incorporating Social Share Buttons to Enhance User Engagement on Your WordPress E

Looking to enhance my product page by adding social icons right below the 'Add to Cart' button. The product page URL is https://flowersforeveryone.co.za/product/cheerful-orange-tulips/. I already have a 'social menu' set up. How can I ...

Positioning Div at the Bottom of a Interactive Flip Card Using Bootstrap 4

My current project features a creative flip image card created using bootstrap and js. On the back of the card, there is a title, a main text body, and a few small additional pieces of information. My goal is to have these three small bits of information a ...

Creating a jQuery alertbox that is triggered by specific elements in an anchor tag

I am working on an HTML page that contains 50 A tags. I am trying to figure out how to create an alert based on a specific element inside the A tag. Here is an example of what I am looking for: <a href "something">click to see the alert</a> ...

Trouble submitting lengthy text in HTML form

Creating a simple HTML form <form method="post" action="process.php"> <label>First Name</label> <input type="text" name="first_name" /> <br /> <label>Last Name</label> <input type="text" nam ...

Executing a webservice method in an html page using javascript without the need to refresh the page

Is it possible to call a webservice from an index.html page using JavaScript? My webservice is located at "localhost/ws/service.asmx" and the specific web method I want to call is called HelloWorld. The index.html page contains an HTML submit button whic ...