【问题标题】:How can i link button in html to another class/div如何将 html 中的按钮链接到另一个类/div
【发布时间】:2019-01-27 10:51:09
【问题描述】:

我有一个 1 页的网站,如果我单击它以链接到我的页脚,如何链接我的按钮 我的页脚 ID 是 Footersite

我的代码:

<div class="openbutton">
    <a href="Footersite">
       <p style="color: white; font-size: 17px;">Contact us</p>
    </a>
</div>

但它并没有下降。我该如何解决这个问题?

【问题讨论】:

标签: html button hyperlink footer


【解决方案1】:

即使您可以使用锚标记来实现这一点,但这并不是唯一的方法。使用button 元素,您可以实现这一目标

HTML 按钮

div {
  margin-top: 800px;
  width: 100px;
  height: 100px;
  background: tomato;
}
<button onclick="window.location.href='#abc'">Button</button>
<div id="abc"></div>

DEMO

如果你想要一个锚元素,那么

锚标记

div {
  margin-top: 800px;
  width: 100px;
  height: 100px;
  background: tomato;
}
<a href="#abc">Link</a>
<div id="abc"></div>

【讨论】:

    【解决方案2】:

    只需使用锚链接即可实现:

    <div class="openbutton">
    
      <a href="#Footersite">
        <p style="color: white;font-size: 17px;">
          Contact us
        </p>
      </a>
    
    </div>
    
    <a name="Footersite"></a>
    <div style="margin:1000px 0;">
      Footersite
    </div>

    【讨论】:

    • 如果是类呢?
    • 你需要 Javascript 来处理类名
    猜你喜欢
    • 2023-03-29
    • 2019-08-29
    • 2019-11-29
    • 2016-04-21
    • 2018-02-23
    • 2019-03-03
    • 2016-11-20
    • 2016-01-26
    • 1970-01-01
    相关资源
    最近更新 更多