Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth scrolling with just pure css [duplicate]

Tags:

How can I make a smooth scrolling with just pure css.

I have this code Fiddle

HTML

<a id="up" href="#down">down</a> <div class="up"></div>  <a id="down" href="#up">up</a> <div class="down"></div> 

CSS

.up {     width:100px;     height: 600px;     background-color: red; }  .down {     width:100px;     height: 400px;     background-color: yellow; } 

I know :target can help but I don't know how to use it with transition.

like image 650
Hayi Avatar asked Mar 07 '14 09:03

Hayi


People also ask

How do you navigate to another page with a smooth scroll on a specific ID?

Modern Browsers detect the hash in the url and then automatically open that part. So, if you want to scroll smoothly to that part instead, you first need to reset the scroll position to 0 and then add smooth scrolling. // direct browser to top right away if (window. location.

How do I smooth a scroll to an element?

To scroll to an element, just set the y-position to element. offsetTop . The SmoothScroll.


1 Answers

You need to use the target selector.

Here is a fiddle with another example: http://jsfiddle.net/YYPKM/3/

like image 114
sidney Avatar answered Sep 28 '22 03:09

sidney