Unfortunately this can not be done using CSS, to achieve this desired effect you will have to use Javascript / jQuery.
Here's an example below of how you can do this using jQuery, and you also have a JSFIDDLE LIVE EXAMPLE .
Well, first for the jQuery code below to work, you need to implement the jQuery Library, before closing the </head>
tag on your site ( if you have not already implemented it).
For this you have to add the following line of code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
ThenyoucaninsertthejQuerycodethatwillhandlethesmoothscrollingeffectfortheanchorlink,whichcanalsobeimplementedshortlyafterthislineofcodeabove.Everythingtogetherwilllooklikethis:
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
var $doc = $('html, body');
$('a').click(function() {
$doc.animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);
return false;
});
</script>
Note: The above jQuery code was created by pointing to the <a>
tag, but
the recommended would be to create a class
specifies only to handle
with this, such as class="scrollSuave"
and add this
class to the links that you want this effect to be applied, for example:
<a href="#contact" class="scrollSuave">Contato</a>
<a href="#about" class="scrollSuave">Contato</a>
etc ...
Of course, also make this change in the jQuery code by pointing it now at class="scrollSuave"
in this line:
$('.scrollSuave').click(function() {
In this way we are only pointing this script to the links that we want the effect to apply and not to all <a>
links.
Here's a link to an example: link