tips for preventing content from overlapping in flexbox headers

Custom CSS Styles for Menu Bar

* {
    margin: 0;
    padding: 0;
}
body {
    background: white;
    font-family: 'Helvetica Neue', Helvetica;
    font-weight: 400;
    font-size: 1.05em;
    line-height: 1.6rem;
    color: white;
    font-size: 1.2em;
}
header {
    position: fixed;
    background: #d777ea; /*light purple*/
    width: 100%;
    display: block;
}
header > nav > ul {
    display: flex;
    margin: 0;
    padding: 0;
    justify-content: flex-start;
    list-style: none;
    flex-wrap: wrap;
}
header > nav > ul > li {
    margin: 0;
    flex: 0 1 auto;
    position: relative;
    transition: 0.2s;
    cursor: pointer;
}
header > nav > ul > li:hover {
    background: #aa64e0; /*dark purple*/
}
header > nav > ul > li > ul {
    /* dropdown */
    position: absolute;
    background: #76a1e8; /*light blue*/
    display: none;
    list-style-type: none;
    margin: 0;
    padding: 0;
}
header > nav > ul > li:hover > ul {
    /* dropdown */

    display: block;
    width: 220px;

}
header > nav > ul > li > a {
    color: white;
    display: flex;
    font-size: 1.5rem;
    text-decoration: none;
    padding: 1rem 1.5rem;
    letter-spacing: 1px;

}
header > nav > ul > li > ul > li {
    display: block;
}
header > nav > ul > li > ul > li > a {
    text-decoration: none;
    color: white;
    display: flex;
    letter-spacing: 1px;
    cursor: pointer;
    padding: .25rem 1.5rem;
}
header > nav > ul > li > ul > li:hover {
    background: blue;
}
header > nav > ul > li > a > i {
    margin-left: 5px;
}
input {
    padding: .25rem;
    width: 100px;
}
input:invalid {
    border: 2px solid red;
}
header > nav > ul > li > ul > li > input:invalid + button {
    background: red;
    cursor: not-allowed;

}
button {
    padding: .25rem;
}

An HTML Header and Image Section

<header>
    <nav>
      <ul>
        <li><a href="#">Teams<i class="fas fa-caret-down"></i></a>
            <ul>
                <li><a class="preset-id" data-schoolid=13318>Huron</a> </li>
                <li><a class="preset-id" data-schoolid=99999>Pioneer</a></li>
                <li>
                    <input type="number" min="1" max="100000" class="custom-id-value" placeholder="School ID #" required>
                    <button class="custom-id"> Go </button>
                </a>
                </li>
            </ul>
        </li>
        <li><a class="show-calendar">Calendar</a></li>

        <li><a class="show-athletes">Athletes</a></li>
    </ul>
    </nav>
</header>
<main>
    <image src="https://www.w3schools.com/w3css/img_lights.jpg"></image>
</main>

Issue with Content Placement when Displayed

The content overlaps the header bar, seeking a way to prevent this and have it positioned below the header. No movement of content below the dropdown menu should occur upon activation.

Link to JsFiddle Example: https://jsfiddle.net/g870xy3d/36/

Answer №1

To achieve the desired result, simply adjust the margin-top property in the main element to match the height of the header. Additionally, make sure to include top:0 in the styling for the header:

header{
  top:0;
  position: fixed;
  background: #d777ea; /*light purple*/
  width: 100%;
  display: block;
}

main{
   margin-top: 57px;
}

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

cusel.js encountered an error due to attempting to use the 'in' operator to search for 'using' within the specified error

I attempted to implement the cusel.js (styled selects) library on my select elements, but unfortunately it's not functioning as expected. The selects change visually, however when I try to scroll through the options using jscrollpane, an error that I ...

Adaptable/Responsive Layout

Thank you for taking the time to look at this post. I am currently working on gaining experience with html, CSS, and JavaScript in hopes of entering the Front End Developer field. Today, I encountered a few issues while working on this adaptive design. He ...

Is it possible for Javascript to fetch a sound from the server once and then duplicate it across n different objects when loaded multiple times?

Incorporating Javascript into my work is crucial. Here's an example: sound = []; for (var i = 0; i < 20; i ++) sound[i] = new Audio("source.wav"); My concern is whether the sound will be retrieved from the server 20 times, or just once. I a ...

Track and store your current progress with a countdown deadline using a progress bar in Bootstrap 4

I am working on a unique way to showcase a dynamic countdown date progression using Bootstrap 4 progress bar. The challenge lies in displaying the progress percentage based on a specific date input format from an admin. After retrieving the deadline date ...

The modification of HTML styles

How can I change the style (width, color etc) of all 8 functions like this? function my(){document.getElementById("question1").innerHTML="THIS QUESTION"+ "<br>" +"<button onclick=answer1() id=ques1 >first answer</button>" +"<button ...

css effect of background image transitioning on mouse hover

Is there a way to have an element on my webpage with a background image that follows the movement of the mouse when hovered over? I want it to be similar to this website: This is the HTML code I currently have: <section id="home" data-speed="3" data-t ...

Insensitivity to case in jQuery situations

I am working on a cshtml page that contains a select option. <div class="t-input"> <select class="tia-input c-combo" data-bind="options: artists, optionsText: 'content', optionsValue: 'id', optionsC ...

Determine the true size of a hidden element that was dynamically generated

I've designed a div element that initially displays only 180 characters, hiding the rest of the content. When a user clicks on the 'viewmore..' link within this partially hidden div, all the content becomes visible and a 'showless...&a ...

Rearranging the @use directive in Sass

Here are some style snippets: tokens.scss .text-center { text-align:center; } .bold { font-weight: bold; } @mixin text-style-1 { font-size: 1.2rem; font-weight: bold; } component/card.scss @use "../token.scss" as tokens; .card { @i ...

Unable to locate CSS file in subfolder

Comparing two scenarios: Scenario 1 is problem-free, but issues persist in scenario 2. Review the details below: Scenario 1: MasterPages: Main\MasterPages.master Css : Main\Theme\CSS\ Javascript : Main\Theme\Javascrip ...

Unable to connect the index.html file with the style.css file located in a different folder

I'm having an issue linking my style.css file to my index.html file. They are both located in different folders. Here is the folder structure: /parent /src/index.html /css/style.css I have attempted using the following code snippets: <link re ...

Animation for Collapsing Dropdowns within a Bootstrap Framework

I am facing an issue with the dropdown within the Navbar collapse. I want to implement a smooth animation for the dropdown/collapse instead of it abruptly appearing. The navbar-toggler button handles the animation perfectly, but the internal dropdown does ...

Why does the border-radius property not work on my image elements?

Greetings! I have defined an ID named #img in my stylesheet with the property border-radius: 15px; In my HTML, I assigned this ID to a div. However, the images within that div are not getting rounded corners as expected. When using the img selector, it aff ...

Replacing one <div> with another <div> using a clickable link within the divs

In one of my web pages, there is a div that I'll refer to as div1. Within this div, there is a link called 'Link1'. My goal is to click on Link1, triggering the replacement of div1 with div2. Inside div2 there will be another link, let&apos ...

unable to execute PHP code

I am attempting to execute a PHP file that will update a database. On Chrome, I am encountering this error: https://i.sstatic.net/3ruNL.png This is the code I have in my index.html file: <!DOCTYPE html> <html> <body> <input type ...

Is there a way to customize the color of disabled columns within a Mat-Table?

I have customized my table by disabling certain columns and now I want to distinguish them with different colors. To achieve this, I created a TypeScript function that changes the CSS using the class ".disabledRange". I came across suggestions about using ...

What is the most efficient method for sorting a list of nodes based on a specified array?

Below is the HTML code representing a list of elements: <div class="container"> <div class="apple-0">first-apple</div> <div class="apple-1">second-apple</div> <div class="apple-2">third-apple</div> ...

Pictures show up on chrome, yet fail to appear on Firefox

Why do my images show up correctly on Chrome and Safari, but not on Firefox? Any assistance would be greatly appreciated. Here is the code snippet I am using: HTML: <div class="clearearlanding"></div> CSS: div.clearearlanding { content: ...

Can you show me how to use vuejs to implement h2 tags?

Within the article, there are H2 tags that I want to use as a table of contents. However, despite attempting methods like Replace and substring, I haven't been able to isolate only the H2 tags from the content. The post content is structured in JSON f ...

Using JQuery to dynamically change className based on specific logic conditions

I am struggling to dynamically change the class name of a div based on the text inside another div using jQuery. Here is an example of the HTML structure: <div class="div-overlay"> <a class="image" href="https://www.e ...