goksel
goksel

Reputation: 4580

Prevent scrolling for :target selector?

Is there way to prevent scrolling for :target selector, because when a link is fired, scrolling is not smooth.

Upvotes: 0

Views: 1579

Answers (1)

Gerben
Gerben

Reputation: 16825

You can only prevent scrolling by using JS. ... But than :target will no longer work. You could just set a target classname with js and use that. Something like:

<a href="#name" onclick="document.getElementById(this.href.substr(1)).className='target';return false">

css:

:target /* no JS browsers */
, .target /* JS */
{
/* rules */
}

Upvotes: 3

Related Questions