Ensure the menu bar remains at the top of the page without using the position:

Check out this awesome fiddle here! My menu bar looks great at the top, but for some reason it won't stay in place when the user scrolls down. I've tried adding position:fixed to the CSS under the first #cssmenu, but it messes everything up.

Here's the snippet code:

@font-face {
    font-family:'Abraham Lincoln';
    src: url(../fonts/Abraham-Lincoln/AbrahamLincoln.ttf);
}
@font-face {
    font-family:'Ingleby';
    src: url(../fonts/Ingleby/Ingleby_regular);
}
body {
    font-family:'Ingleby';
    background-image: url(../Images/background.jpg);
    background-repeat: repeat;
    width: 100%;
    margin: 0px;
    padding: 0px;
}
.clearfix:after {
    display: block;
    clear: both;
}
h2.names {
    font-size: 36px;
    text-align: center;
    font-family:'Abraham Lincoln';
}
h3.date {
    font-size: 28px;
    text-align: center;
    font-family:'Abraham Lincoln';
    margin-top: -20px;
}
h4 {
    font-size: 20px;
    text-align: center;
    font-family:'Abraham Lincoln';
}
p {
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    font-size: 16px;
}
.background {
    width: 960px;
    display: block;
    margin: 0px auto;
    margin-top: 0px;
}
footer {
    text-align: right;
    font-size: 12px;
    height: 30px;
    background-color: rgb(59, 58, 76);
    width: 100%;
    padding-top: 5px;
    padding-bottom: 10px;
}
footer a {
...

<p>I absolutely love this webpage!</p>
<p>It is soooooo cool!</p>

Answer №1

This tip can be really helpful. The .before_content class has been added to create a margin between the menu and the content.

#cssmenu {
  position: fixed;
  top: 0;
  width: 100%;
}
.before_content { 
  margin-top: 80px;
}

@font-face {
    font-family:'Abraham Lincoln';
    src: url(../fonts/Abraham-Lincoln/AbrahamLincoln.ttf);
}
@font-face {
    font-family:'Ingleby';
    src: url(../fonts/Ingleby/Ingleby_regular);
}
body {
    font-family:'Ingleby';
    ...
}

/* ------------ */
/*   NEW MENU   */
/* ------------ */
 #cssmenu ul, #cssmenu li, #cssmenu span, #cssmenu a {
    ...
}
#cssmenu {
    line-height: 1;
    background: #141414;
    ...
}
...
:before, #cssmenu ul:before {
    ...
}
#cssmenu a {
    ...
}
...
</div>
    <h2 class="names">Bob + Suzy</h2>

<p>Lorem ipsum ...</p>

Answer №2

Consider inserting the following code snippet at the end of your CSS file:

#cssmenu {
    position: fixed;
    top: 0;
    width: 100%;
}

h2 {
    margin-top: 75px; 
}

Visit this link for a live example.

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

"Revamp your site with Vue and API for dynamic background

I'm faced with an issue where I am attempting to modify the background of a joke fetched from an API, but for some reason, the background is not changing and I can't seem to identify why. The main problem lies in my inability to change the proper ...

What is the best way to embed a section of another website within an iframe and seamlessly guide a user to complete a purchase using a shopping cart?

Seeking advice on how to improve the functionality of my website. Currently, the domain I'm focusing on serves as a landing page, redirecting users to another site for purchases. I've built a separate website for this domain in order to establis ...

Unlock maximum screen viewing on your custom video player with these steps to activate fullscreen

I'm having an issue with my basic video player - when toggling fullscreen, it doesn't fill the whole screen even though I tried using .fullscreen{width:100%} without success after searching for a solution. html <div class='player-contai ...

What techniques can I implement using JavaScript or CSS to create a slightly transparent effect on my text?

I am currently developing a website that features changing background images. I am looking to have the text on the site mimic the color of the backgrounds, but not so much that it becomes difficult to read. How can I make the text transparent in this man ...

Adding a class name to the three active, visible, and shown slides in SwiperJS is a simple process that can be done by

Currently, I am working on customizing a carousel in Swiper with slidesPerView={3}. My goal is to style the sliders that are not visible on the screen. I have made multiple attempts to achieve this: First, I tried adding the attribute slideActiveClass="sw ...

Issue with Django app: Bootstrap 4 modal hidden behind background

Having exhaustively researched this issue, I am still unable to resolve it with the outdated Bootstrap solutions available. The problem arises when I click on the button - the modal appears behind the background instead of in front. Most suggestions indica ...

The stunning fade effect of Magnific Popup enhances the visual appeal of the inline gallery

I'm currently using magnific popup for an inline gallery, but I'm not seeing any effects. I would like to have a fade effect when opening/closing the popup. Can someone assist me with achieving this? https://jsfiddle.net/gbp31r8n/3/ [Check o ...

Incorporating a technique for aligning text towards the right as the number of characters or digits expands

I'm designing a game user interface with a money indicator. Let's imagine the player has 0 dollars in their wallet, it should appear like this: https://i.stack.imgur.com/35eoh.png Please note that it is located in the upper right corner. The p ...

A step-by-step guide to displaying a label component upon clicking an AjaxLink

How can I display data from a JSON file when an AjaxLink is clicked? The code I have implemented is not working, so I would appreciate any corrections or suggestions. Additionally, I am wondering if it's possible to add a label inside AjaxLink. Thank ...

Implementing a delay between two div elements using jQuery

I have two Divs with the class "sliced", each containing three images with the class "tile". When I animate using jQuery, I am unable to add a delay between the "sliced" classes. However, I have successfully added a delay between the "tile" classes. index ...

The ajax method for loading an xml file results in displaying the undefined message

When attempting to fetch content from an xml file using ajax, the page initially displays "undefined". However, upon refreshing the page, the content loads successfully. Take a look at my code snippet below: $.ajax({ type: "GET", url: "xm ...

Establishing the REM value for all CSS properties

My goal is to implement the use of rem units throughout my website. However, relying on the standard rem-to-px conversion rate doesn't feel very intuitive: 10px = 0.625rem 12px = 0.75rem 14px = 0.875rem 16px = 1rem (base) 18px = 1.125rem 20px = 1.25r ...

In React, the entire component refreshes every time the modal is opened

<ThemeProvider theme={theme}> <GlobalStyle /> {componentName !== 'questionaire' && componentName !== 'activityResult' && <CardWrapper />} <ErrorModal ...

Tips for altering the color of an image using CSS attributes

I am looking to create a male Head component in this design draft and modify the CSS according to the skin prop. I have attempted to use filter and mix-blend-mode properties, but have not found a solution yet. Any guidance on how to achieve this would be ...

Incorporate a progress bar and delete functionality for uploading files in PHP

I am currently working on creating a file uploader that includes a progress bar and a close button. However, I have encountered some major issues with the code. The progress bar continues to show endlessly, and the main problem is that it deletes the file ...

How much data is considered a suitable amount to be loaded on a single page?

Currently, I am developing a page for a photographer on the website page. To enhance user experience, I have implemented a jQuery script that allows users to flip through images seamlessly. Initially, I was replacing just the src attribute of each image, b ...

Difficulty encountered when trying to update a re-updated HTML DOM using Flask

I have a flask dropzone for file uploads, and after each upload I want to display a log text on the website. While it currently works, there is an issue where the log text does not update after the second upload. The website continues to show the text from ...

What could be the reason why this LESS CSS is not taking effect?

Why won't this stylesheet load properly? The desired background color is supposed to be similar to cadetblue. You can view my page with the linked home.less.css at: ...

Using JQuery to manipulate `this`, its children, its siblings, and more

Can anyone help me determine the most effective way to send data from a get request to a specific div? My challenge is to send it only to a div that is related to the one triggering the action. For example, when I click on the message_tab, I want to send t ...

iPhone height is not correct

One issue I faced was when trying to view a webpage in landscape mode on iPhones (specifically testing on model SE, but it appears that many people are experiencing the same problem with other iPhone models). I have created a simple example below, consist ...