I have a scrolling sidebar menu. So when I select a menu item it should appear at the top position of the sidebar. There is no problem setting up the active menu. I got it. But I can't set the top position of the sidebar. Please do not recommend jQuery. Instead I was advised to use plain JavaScript Here is some code reference
.sidebar{ height:100px overflow-y:scroll; } .sidebar ul li{ padding:30px; }
<!-- CSS --> <!-- html --> <div class="sidebar"> <ul> <li>item1</li> <li>item2</li> <li>item3</li> <li>item4</li> <li>item5</li> <li>item7</li> <li>item8</li> <li>item9</li>........ <li>item100</li> </ul> </div>
P粉4615998452024-02-18 13:49:54
Pure CSS solution using :target
pseudo-class, flexbox
layout, and order
properties.
.sidebar { background-color: #ddd; height: 200px; overflow-y: scroll; } .sidebar ul { display: flex; flex-direction: column; margin: 0; } .sidebar li { padding: 1em; order: 1; } .sidebar :target { background-color: #aaa; order: 0; }