Prevent an element from covering another [closed]

There are two solutions I can think of quickly off the top of my head. You can either give the #headercontainer element a z-index CSS property

#headercontainer {
    /* ... other CSS ... */
    z-index: 1000;
}

… or you can do it the way I think it should be done…

#headercontainer {
    /* ... other CSS ... */
    position: fixed;
    top: 0px;
}

#contentcontainer {
    /* ... other CSS ... */
    margin-top: 125px; /* this should be at least the height of the header */
}

In the second solution, you don’t have to worry about which element is hovering over which other element. The #contentcontainer element is properly pushed down under the #headercontainer element so that they have no overlap.

Leave a Comment