Logo remains in place when scrolling halfway down the page

I have a logo that I want to stay halfway up the home page when scrolling, as if fixed in place until it reaches the footer.

 body {
  background-color: #fff;
  margin: 0;
}

nav {
  position: sticky;
  top: 0;
  width: 300px;
  height: 80px;
  margin:45px auto -50px; 
  background-color: yellow;
}

header {
  height: 30vh;
  background-color: #fff;
}

main {
  height: 200vh;
  background-color: #eee;
}
   
<nav>
  <div class"logo">logo</div>
</nav>
<header>
</header>
<main>
<p>body text</p>
</main>

Do you think this is feasible?

Answer №1

 body {
  background-color: #fff;
  margin: 0;
}

nav {
  position: fixed;
  top: 0;
  width: 300px;
  height: 80px;
  margin:45px auto; 
  background-color: yellow;
  left: 50%;
  margin-left: -150px;
}

header {
  height: 40vh;
  background-color: #fff;
}

main {
  height: 200vh;
  background-color: #eee;
}
   
<nav>
  <div class"logo">logo</div>
</nav>
<header>
</header>
<main>
<p>body text</p>
</main>

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

Header with Sticky Behavior and Smooth Slide Down Animation

I am trying to achieve a scroll effect on my page where the header will move up when scrolling up, but at position 150 it should smoothly slide down and stay fixed at the top. I have tried various methods but haven't been able to get it right. Can som ...

Would you say the time complexity of this function is O(N) or O(N^2)?

I am currently analyzing the time complexity of a particular function. This function takes a string as input, reverses the order of words in the string, and then reverses the order of letters within each word. For example: “the sky is blue” => ...

Retrieving input data when utilizing ng-file-upload

I need help with uploading images and their titles using ng-file-upload in the MEAN stack. I am able to save the image successfully, however, I'm facing difficulty in retrieving the data sent along with it. Controller: module.exports = function ($sc ...

Issues with webpage responsiveness, width not adjusting correctly

Just completed coding my website and now I'm facing a new challenge. I am focusing on making it responsive for tablet screens (768px) starting with the header section, but for some reason, the modifications I make in the responsive.css file are not ta ...

Using clearInterval() within setInterval does not necessarily halt the execution of setInterval

I have set up an ajax GET request to send every 5 seconds using JavaScript setInterval. My goal is to stop the ajax calls when the response status is 'COMPLETED'. I have added a clearInterval within an if condition to achieve this, but unfortunat ...

My goal is to ensure that when a user copies the URL of a website from the address bar and pastes it into a social media app, the link automatically transforms into the title of

Similar to the process in Airbnb where a copied URL is pasted in Slack and replaced with specific text along with the site URL I have tried adding og:title, description, and images, but cannot figure out how to handle this issue. Any assistance would be a ...

Prevent removal of h2 tag within a contenteditable segment

Can a section be made permanent within a contenteditable element to prevent user removal? I have an h2 tag inside a contentEditable div. I do not want the user to be able to edit the h2 tag, so I set contentEditable=false, but they can still select and de ...

Tips for displaying a div element inline with precision?

I have HTML code to create multiple small boxes, each with a name retrieved from an object called graphdata. <div ng-repeat="a in graphdata" class="inline"> <div class="legend-box"style="background-color:{{a.color}};"> </div> ...

The command '.' is unable to be executed as an internal or external command, executable program, or batch file when using npm start -- -e=stag -c=it

After executing the command shown below npm start -- -e=stag -c=it An error is generated: ./scripts/start.js -e=stag -c=it '.' is not recognized as an internal or external command, operable program or batch file. What can be done to resolve th ...

Developing a continuous running test loop

Currently, I have a code that runs fine, but I am looking to modify it to run in a loop that counts the number of elements with the class="socal" and tests each link. module.exports = { 'Unitel Fitness - click' : function (browser) { bro ...

Headers cannot be set once they have already been sent in NodeJS

Here is the code where I authenticate users in a group, push accounts into an array, and save them using a POST request on /addaccount. groupRouter.post('/addaccount', Verify.verifyOrdinaryUser, function(req, res, next) { Groups.findById(req.bod ...

Creating HTML Divs with Equal Heights

I have written this JavaScript code, but I feel like there might be some redundancy. Does anyone have suggestions on how to improve and optimize this code? var boxHeights = []; $('.box').each(function() { boxHeights.push( $(this).outerHeight ...

Shorten the text in a flex container using ellipsis and flex-grow

I have a "table" built using flex and I need to truncate the text in the first column if there isn't enough space, keeping it on a single line all the time. .parent { display: flex; border: 1px solid black; gap: 10px; } .first-column { bor ...

What are some ways to utilize symbol fonts such as marvosym within a web browser?

Are you looking to use special LaTeX fonts like \Pluto from marvosym in your web development projects? Wondering how to display this symbol with HTML / JavaScript / CSS without relying on an image? You can download the font from This symbol corresp ...

Tips for looping through each cell in a column of a DataTable to verify its content

I have a table generated using the jquery DataTables API. One of the columns displays word frequencies for each word in the table. If a frequency is less than 40, I want to change that cell to display "unranked" instead of the actual number. How can I ite ...

Steps to access the most recent eventName (determined by date)

I am working with two arrays var events=["DELIVERED", "OUT TO DELEVERY", "REACHED WAREHOUSE", "DEPARTED"]; var eventDetails= [{ "source" : "application" "DateTime": "2016-05-12 11:20:00", "eventName" : "DELIVERED" }, { "source" : "application" "DateTime" ...

What is the easiest method to design an email subscription form that remains fixed on the top right corner of the screen?

Looking for advice on setting up a sleek email signup bar that remains at the top of the browser while users scroll and navigate through different pages. I am working with WordPress and have jquery already loaded, but have not yet worked with either. Up ...

Using axios to modify and enhance the HTML content of a webpage

Utilizing axios and an API, I am able to retrieve a page's HTML, make edits to it, and then send it back via a POST request to the API. While successful in retrieving and editing the HTML content, I'm encountering difficulty in updating or changi ...

Enhancing this testimonial slider with captivating animations

I have designed a testimonial slider with CSS3 and now I am looking to enhance it by adding some animation using Jquery. However, I am not sure how to integrate Jquery with this slider or which plugins would work best for this purpose. Can anyone provide g ...

Singleton pattern for iFrames sharing the same origin

I have developed a web application that runs on multiple iframes within a parent window, similar to a modified version of GWT. Rather than each individual iframe accessing our backend service separately, I am attempting to have them share the data service ...