How to make it so that when you click on a link with a stub that is, for example in the middle of the page, does not flip to the top of the page? To position on the page remained in that place.

.middle { margin-top: 400px; } 
 <ul class="middle"> <li><a href="#">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅</a></li> <li><a href="#">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅</a></li> <li><a href="#">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅ с Π±Π»Π°Π½ΠΊΠΎΠΌ</a></li> </ul> 

  • Believe it or not, I wondered this question 15 minutes ago;) - midia
  • Why then is the link even needed? - andreymal
  • @andreymal buttons do :) - midia
  • @midia buttons have their own tag :) - andreymal

2 answers 2

Add "onclick" attribute

 <a href="#" onclick="return false;">тСкст</a> 

 .middle { margin-top: 400px; } 
 <ul class="middle"> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅</a></li> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅</a></li> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅ с Π±Π»Π°Π½ΠΊΠΎΠΌ</a></li> </ul> 

    Remove the href attribute, if href needed, you can add onclick="return false;" .

    The link is usually created to be a link or an anchor or at the initial stage of development when it does not matter yet.

    If you need something like a button to execute an event, you do not need to do this with the a tag, for example, you can take a span tag and add styles to it

     .middle { margin-top: 400px; } 
     <ul class="middle"> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ ΠΎΡ€ΠΈΠ³ΠΈΠ½Π°Π»ΡŒΠ½Ρ‹Π΅</a></li> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅</a></li> <li><a href="#" onclick="return false;">ΠŸΠΎΡ‡Ρ‚ΠΎΠ²Ρ‹Π΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Π±ΡƒΡ€Ρ‹Π΅ с Π±Π»Π°Π½ΠΊΠΎΠΌ</a></li> </ul>