Ways to position a container div below a menu through CSS

I'm having trouble getting the container div to display below the menu instead of alongside the header. Can someone help me fix this issue? Here is my HTML and CSS code:

<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>Renault Club Macedonia - Welcome</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class="web">
    <div id="header">
        <div class="logo">
          <a href="#"><img src="images/logo.png" alt="Logo"/></a>
        </div> <!-- logo end -->

            <div class="menu">
              <ul>
                  <li class="active"><a href="#" style="color:#ecd302">Home</a></li>
                  <li><a href="#">Forum</a></li>
                  <li><a href="#">Club</a></li>
                  <li><a href="#">Membership</a></li>
                  <li><a href="#">Gallery</a></li>
                  <li><a href="#">Classifieds</a></li>
                  <li><a href="#">Contact</a></li>
              </ul> <!-- main menu end -->
            </div> 
    </div> <!-- header end -->  
     <div class="container">

        <p id="petrol">Prices taken from Makpetrol *prices are in denars / liter </p>

     </div>
</div><!-- web end -->

@charset "utf-8";

body {
margin:0;
padding:0; 
width:960px; 
background:#e2e2e2; 
}

a {
text-decoration:none;
color:#ffffff;
text-shadow:1px 1px #000000;
}

a:hover {
text-decoration:none;
color:#a6a5a5;
}

a:active {
text-decoration:none;
color:#ecd302;
}

.web {
width:960px;
margin-left:auto;
margin-right:auto;
}

#header {
 background-repeat:no-repeat; 
 display:block; 
 margin:auto; 
 padding:0px; 
 height:110px; 
 background:#ecd302;  
 position:absolute;
 top:0; 
 left:0; 
 right:0; 
}

.logo { 
background-repeat:no-repeat; 
width:305px;
height:85px; 
float:left; 
margin:10px 0 0 202px;
}

.menu {
background:#4b4b4b;
text-transform:uppercase;
word-spacing:32px;
font-size:20px;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-decoration:none;
text-align:center;
border-bottom:1px solid #000;
border-top: 1px solid #000;
display:block;
position:absolute;
top:105px;
left:0;
right:0;
}

ul {

}


li {
display:inline;
}

.container {
background:#929191;
left:0px;
right:0px;
text-align:right;
width: 960px;
font-size:12px;

}

If you need more information or clarification on my question, please feel free to reach out to me.

Answer №1

Remember, when you use position: absolute, the element doesn't take up any space, causing other elements to fill that position. This can result in elements overlapping, which is usually not desired. Only resort to position: absolute when absolutely necessary.

I have removed position: absolute from both #header and .menu. This eliminates the need for top, left, and right declarations. You can also omit defining the width of the body since it is already specified for .web. Furthermore, I have made some adjustments to the styles of .logo and #header to achieve the desired outcome as shown in the screenshot.

Check out the updated code: http://jsfiddle.net/azq50bsd/5/

body {
margin:0;
padding:0;
background:#e2e2e2; 
}

a {
text-decoration:none;
color:#ffffff;
text-shadow:1px 1px #000000;
}

a:hover {
text-decoration:none;
color:#a6a5a5;
}

a:active {
text-decoration:none;
color:#ecd302;
}

.web {
width:960px;
margin-left:auto;
margin-right:auto;
}

#header {
 background:#ecd302;
}

.logo { 
background-repeat:no-repeat; 
width:305px;
height:85px; 
margin:10px;
}

.menu {
background:#4b4b4b;
text-transform:uppercase;
word-spacing:32px;
font-size:20px;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-decoration:none;
text-align:center;
border-bottom:1px solid #000;
border-top: 1px solid #000;
display:block;
}

ul {

}


li {
display:inline;
}

.container {
background:#929191;
left:0px;
right:0px;
text-align:right;
width: 960px;
font-size:12px;
}

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

Locating the elusive sequence number within a document

Greetings, I am currently trying to locate a missing number within an xml file but seem to be encountering some challenges. Any suggestions or ideas would be greatly appreciated. Example The file contains an <a> tag with various ids such as page-1, ...

Is it possible to have a getter in vuex dynamically update when another getter's value changes?

Within my vuex store, I have this getter that retrieves authority_count: authority_count (state, getters) { return getters.dataView?.getUint16(4, true) || state.pack.authority_count; } I want authority_count to default to state.pack.authority_count ...

The error message "TypeError: 'undefined' is not an object ('_this.props')" indicates that the property '_this

Having trouble solving this issue. Need assistance with evaluating 'this.props.speciesSelection.modalize' <BarcodeInput speciesSelection={this.props.speciesSelection} species={species[0]} barcode={{ manufacturerValue: ...

Which one should I prioritize learning first - AngularJS or Laravel?

As a novice web developer, I am embarking on my first journey into the world of frameworks. After much consideration, I have narrowed it down to two options: AngularJS and Laravel. Can you offer any advice on which one would be best for me to start with? ...

What is the most effective way to display a card with varying values depending on the user's input in a form?

For a while now, I've been grappling with a particular challenge. In my project, I am utilizing multiple states to display values within a card after they are entered into a form. The first state captures the values and modifies the initial state, whi ...

Add a CSS file to the browser-sync with proxy functionality

Currently, I have a script that I utilize to proxy a live website in order to make CSS modifications. Instead of replacing the online CSS file with a local one using a rewrite, I am exploring the possibility of injecting an entirely new file below the exis ...

excess margin running along the left side of each page

When visiting http://tadris3.ir/, one may notice a peculiar space on the left side of all pages. Can anyone assist in resolving this bothersome issue? https://i.sstatic.net/MsX1a.png ...

Safari's problem with CSS transitions

This issue is specific to Safari, as it has been tested and works fine in Chrome, Opera, and Firefox. Upon hovering over a certain div (1), a child div (2) slides out by adjusting the left property. However, the child elements (buttons) within the second ...

How can I resolve the issue of the input field added dynamically by JavaScript not appearing in the PHP $_POST variable?

I have a form nested within an HTML table. Using jQuery, I am dynamically adding input fields to the form. However, when I submit the form and check the $_POST array with var_dump(), the added fields are not showing up. Why is this happening? Below is th ...

Convert former function to use async and await system

I need to convert this function to async, but I am facing an issue where the users object obtained from mapping interactions is not returning data in the expected format. When I run the async function on the client side, my values are showing up as nil. Th ...

The Ajax response is not providing the expected HTML object in jQuery

When converting HTML data from a partial view to $(data), it's not returning the jQuery object I expected: console.log($(data)) -> [#document] Instead, it returns this: console.log($(data)) -> [#text, <meta charset=​"utf-8">​, #text ...

NextAuth: JWT callback that returns an object

I've been working on a project using Next.js (11.1.2) + NextAuth (^4.0.5) + Strapi(3.6.8). The Next Auth credentials provider is functioning correctly. However, I need to access certain user information using the session. I attempted to do this by ut ...

Insert a fresh item into the existing unordered list

Every time I enter something in the prompt, it shows up as "undefined". What I actually want is for whatever I type into the prompt to be added as a new list item. For instance, if I type "Food" in the prompt, I expect to see "Food" appear on the second li ...

The post body is incomplete and is lacking the necessary parameter "To" that

It seems there might be a configuration issue either in the header or the body. Should I make changes to the headers or is it possible that the body is misconfigured? const axios = require('axios'); const url = '/my_url'; const aut ...

What steps should I follow to bring in an animated SVG file into Next.js 13 without losing transparency and animation effects?

How to Include an Animated SVG File in Next.js 13 import Image from "next/image"; export default function Home() { return ( <main className="flex h-screen flex-col items-center"> <div className="container mt-1 ...

There seems to be an issue with the functionality of the AJAX file upload feature in

I've developed a method for file uploading using AJAX technology (pure JavaScript) in CodeIgniter. Here's how it works: 1- I created a script.js file to manage the AJAX/JavaScript upload process. 2- I implemented a controller in CodeIgniter to ...

Navigate Formik Fields on a Map

Material UI text-fields are being used and validated with Formik. I am looking for a way to map items to avoid repetitive typing, but encountering difficulties in doing so. return ( <div> <Formik initialValues={{ email: '&a ...

Retrieve Element By Class Name in JavaScript

How can I modify the border color at the bottom of the .arrow_box:after? Javascript Solution document.getElementsByClassName("arrow_box:after")[0].style.borderBottomColor = "blue"; Despite trying this solution, it seems to be ineffective! For a closer ...

JavaScript code that is condensed for efficiency without sacrificing readability and maintainability

As a novice in the world of javascript, I find that studying pre-existing code helps me learn a great deal. I've encountered some extensive javascript projects with minified code that becomes almost indecipherable when expanded. Most variables and f ...

Unable to invoke the 'apply' method on an undefined object when configuring directions for the jQuery Google Maps plugin

I've gone through the steps in a tutorial to create a jquery mobile google map canvas here, and have attempted to set it up. However, I keep encountering this error in my JavaScript console: Uncaught TypeError: Cannot call method 'apply' ...