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 in Others by Soham
• 8,730 points
12 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 by Aditya
• 7,280 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,050 points
597 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 in Others by Kichu
• 16,050 points
29 views
0 votes
2 answers

How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

answered Aug 12, 2020 in Others by Steve
• 200 points
609 views
0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
174 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
4,257 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,240 points
1,608 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
249 views
0 votes
1 answer

What is the difference between span and div?

The div should be used to wrap sections of ...READ MORE

answered Jan 16, 2020 in Web Development by Niraj

edited Jan 21, 2020 by Niroj 2,182 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 in Others by Aditya
• 7,280 points
16 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP