How does the position sticky property work

0 votes

I want to make the navigation bar stick to the top of the viewport once a user scrolls the page, but it's not working and I have no idea as to why that is and if you can please help, I would be grateful. Have shared my HTML and CSS code:

.container { 
  min-height: 300vh; 
} 
.nav-selections { 
  text-transform: uppercase; 
  letter-spacing: 5px; 
  font: 18px "lato",sans-serif; 
  display: inline-block; 
  text-decoration: none; 
  color: white; 
  padding: 18px; 
  float: right; 
  margin-left: 50px; 
  transition: 1.5s; 
} 
.nav-selections:hover{ 
    transition: 1.5s; 
    color: black; 
} 

ul { 
    background-color: #B79b58; 
    overflow: auto; 
} 

li { 
  list-style-type: none; 
}


<main class="container"> 
      <nav style="position: sticky; position: -webkit-sticky;"> 
            <ul align="left"> 
                <li><a href="#/contact" class="nav-selections" style="margin-right:35px;">Contact</a></li> 
                <li><a href="#/about" class="nav-selections">About</a></li> 
                <li><a href="#/products" class="nav-selections">Products</a></li> 
                <li><a href="#" class="nav-selections">Home</a></li> 
          </ul> 
    </nav> 
</main>
Feb 16, 2022 in Others by Soham
• 9,710 points
706 views

1 answer to this question.

0 votes

Do check if an ancestor element has an overflow set for eg. overflow:hidden, following which try toggling it. You may have to inspect the DOM tree higher than you expect =). This may however, affect your position:sticky on a descendant element.

answered Feb 16, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
2 answers

How does artificial neural network work?

Artificial Neural Networks is a part of ...READ MORE

answered Mar 8, 2019 in Others by SA
• 1,090 points
2,000 views
0 votes
0 answers

How does a tool like SEOMoz Rank Checker work?

i am planning to implant a feature ...READ MORE

Feb 14, 2022 in Others by Kichu
• 19,040 points
350 views
0 votes
1 answer

EXCEL-Function to find how many people does the oldest female live with

You can try something like this: =ROWS(FILTER(B11:B9291, T11:T9291=MAXIFS(T11:T9291,G11:G9291,2))) It ...READ MORE

answered Jan 13, 2023 in Others by narikkadan
• 63,600 points
618 views
0 votes
1 answer

A button in excel sheet does not work for the first time

When you press the Display button, the ...READ MORE

answered Mar 30, 2023 in Others by narikkadan
• 63,600 points
479 views
0 votes
1 answer

Fixed position but relative to container

The issue with "fixed" positioning is that ...READ MORE

answered Jun 28, 2022 in CSS by Edureka
• 12,690 points
10,068 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
10,539 views
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,250 points
2,846 views
0 votes
1 answer

What is a css selector and where is it used?

CSS Selector is a combination of element ...READ MORE

answered Nov 21, 2018 in Data Analytics by Kalgi
• 52,350 points
924 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
714 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP