使用一个按钮移动到页面上的某个ID
问题描述:
因此,我正在制作一个网站(惊喜,惊喜),我在页面顶部有一个按钮,当我点击它时,它什么都不做。我想知道如何解决它。使用一个按钮移动到页面上的某个ID
按钮
<button class="Learn-Link" href="#VideoSlide">Learn How
<div class="Learn-Triangle"></div>
</button>
我想前往
<div class="Slide" id="VideoSlide">
<!--More code here, but not relevant-->
</div>
答
button
没有一个href部件属性,你需要添加你的按钮内的a
标签
#VideoSlide{
position: relative;
top:1000px;
height: 100px;
background: pink
}
<button class="Learn-Link" ><a href="#VideoSlide">Learn How</a>
<div class="Learn-Triangle"></div>
</button>
<div class="Slide" id="VideoSlide">
<!--More code here, but not relevant-->
</div>
答
您可以通过使用javascript
如触发按钮: -
<button type="button" onclick="alert('Hello world!')">Click Me!</button>