Conflict between the top menu and body on the HTML page is causing issues

Encountered an issue with my HTML code:

CSS:

.fixedmenu {
    overflow: hidden;
    background-color:rgb(153,0,51);
    position: fixed; /* Ensures the navbar stays in place */
    top: 0; /* Positions it at the top of the page */
    width: 100%; /* Occupies full width */
    font-size:2em;
}

#bodybox {           
    border:0px;
    width:80%;
    padding:0px;
    margin-left: auto; 
    margin-right: auto;
    background:red;
}

This is the HTML code within the body:

<div class="fixedmenu">
    <div style="float: left;color:white;padding:0.5% 0% 0.5% 3%;">YggDrasil ||</div>
    <div style="float: right;color:white;padding:0.5% 3% 0.5% 0%;"> || Login</div>
    <div style="margin:0 auto; width:300px;color:white;padding:0.5% 0% 0.5% 0%;"> Welcome to YggDrasil. </div>
</div>

Everything was fine until this addition:

<div id="bodybox"> 
    hi  
</div> 

After adding this, the margin of my top menu shifts to the right. How can I fix this?

Answer №1

To ensure everything fits nicely on your window and the new div appears after the menu, you can apply margin: 0; to both body and .fixedmenu, as well as set position:relative; for both elements. Additionally, adjust the width of the menu by using width: 100vw;.

<body>
    <div class="fixedmenu">
        <div style="float: left;color:white;padding:0.5% 0% 0.5% 3%;">YggDrasil ||</div>
        <div style="float: right;color:white;padding:0.5% 3% 0.5% 0%;"> || Login</div>
        <div style="margin:0 auto; width:300px;color:white;padding:0.5% 0% 0.5% 0%;"> Welcome to YggDrasil. </div>

    </div>
    <div id="bodybox"> hi</div> 

</body>

Styles applied:

body{
    margin: 0;
}
.fixedmenu {
    overflow: hidden;
    background-color: rgb(153, 0, 51);
    position: fixed;
    top: 0;
    width: 100vw;
    font-size: 2em;
    margin: 0;
    position:relative;
}

#bodybox {
    border: 0px;
    width: 80%;
    padding: 0px;
    margin-left: auto;
    margin-right: auto;
    background: red;
    position:relative;
}

Final result:

https://i.stack.imgur.com/NY5Yb.png

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 pass values from PHP to an HTML tag?

My initial HTML document includes a form with radio buttons. I want my second PHP file to display a message based on the user's selection, and include some formatting such as text size and color. file.html: <html> <body> <form action ...

What are the steps to create two frames using Twitter Bootstrap?

I'm just starting to work with Twitter Bootstrap and I need some help. Can someone assist me in creating a two-column layout inside the HTML, where the menu in the header stays visible even when scrolled down? I've included my HTML code below. Th ...

What is the correct way to markup the semantic form label assistance text?

When designing a form, there are certain form elements that may need explanatory text to clarify their function. One approach is to wrap this text in a paragraph element, as demonstrated below: label p { margin-top: -1px; font-size: smaller; } <div ...

Enhanced Bootstrap 4 button featuring custom design with text and image aligned on the right side, optimized for flexbox layout

I am looking to design a button-like div that features a flag image alongside the abbreviation of a country. Although I have some code in mind, it doesn't follow Bootstrap's guidelines and I am struggling to adapt it accordingly. <div cla ...

Solving relative paths in NodeJS/Express

My website is calling several scripts, images, styles, etc., from different folders both inside and outside the main folder: File Tree - / - website - scripts - data.js - customJquery.js - styles ...

Is there a way to retrieve the row and parent width from a Bootstrap and Aurelia application?

Is there a way to determine the exact width of a bootstrap grid row or grid container in pixels using Aurelia? I attempted to find this information on the bootstrap website, but I am still unsure as there are multiple width dimensions such as col-xs, colm ...

In Google Chrome, the edges of hexagons appear jagged and not smooth

I have encountered an issue in Chrome where I created a hexagon group using HTML and CSS. While it displays fine in Firefox, the edges of the hexagons appear distorted in Chrome. Here are my code snippets: HTML <div class="col-sm-12 margin-left-100" i ...

When the user saves the changes on the pop-up window, the main window will automatically refresh

I currently have a calendar feature that allows users to create, edit, and delete appointments. When a user clicks on the new appointment button, it opens a window above the calendar interface. Once the user fills out the necessary fields and clicks save, ...

React Application not reflecting recent modifications made to class

My current project involves creating a transparent navigation bar that changes its background and text color as the user scrolls. Utilizing TailwindCSS for styling in my React application, I have successfully implemented the functionality. // src/componen ...

"Troubleshooting problems with the display:none property in a media

Encountering a small dilemma with media queries within my HTML. One of the sections in my code contains the following: <div class="header-left"> </div> <div class="header-center"> <ul> <li class="end"> ...

Browser refusing to acknowledge jQuery/JavaScript (bootstrap)

Here is where I include the necessary jQuery libraries and my custom jQuery code: <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script src= ...

Utilize JQuery to implement fading effects for clicked elements in a webpage

I've been using a rollover JavaScript plugin to create smooth transitional effects when users hover over clickable page elements. Everything was going well until I decided to switch to making ajax calls instead of page loads for dynamic content. The p ...

The form submission messages that are being received are appearing blank, even when the name field is populated with an

Hey there! I'm experiencing an issue with my form. Even though I've set the name attribute to "" for all fields, the submitted data comes back blank in my email. Here's a snippet of my code: <div class="col-lg-6 ...

Using jQuery to insert PHP code into a <div> element

In our capstone project, I'm looking to implement a dropdown calendar feature. I initially attempted to use ajax within a dropdown Bootstrap 4, but encountered issues with collapsing. As an alternative, I am considering utilizing the include method. A ...

The challenge with linking within Layerslider

Having some trouble with an external link to a specific layerslider slide (html version, NOT wordpress). Here is the webpage in question: After reaching out in the support forum, I was advised to use this javascript: <a href="javascript:void(0);" onc ...

Creating a Web Form in Outlook Using the POST Method

Seeking help in creating an HTML email featuring two interactive buttons - Approve and Reject. I have successfully generated the HTML email and sent it to Outlook. Snapshot: The HTML code within the email: <!DOCTYPE html> <html lang="en" xmlns ...

Placing a Label Next to an Input Field using Bootstrap 4

Is there a way to position the label right next to the input form? I've attempted different methods without success. Could you please review my code below? <div class="modal-body"> <form class="form-horizontal"> <div cl ...

Connecting MySQL to HTML: Step-by-step guide

I am currently working on building a website through coding in HTML using gedit. My goal is to have a login or registration feature on the homepage, which will then direct users to their own personalized page on the site. On this page, they should be abl ...

Files are nowhere to be found when setting up an angular project

After creating an Angular project, I noticed that some key files were missing in the initial setup, such as app.modules.ts and app-routing.modules.ts The project was generated using the command ng new name Here is a screenshot displaying all the files th ...

Vuetify's scrolling list feature allows for smooth navigation through a list

Check out my Vuetify code snippet that utilizes a list: <v-list> <v-list-tile v-for="user in users" :key="user.id" avatar @click="" > <v-list-tile-content> < ...