【问题标题】:I am trying to make my buttons clickable so I have a link to a website using h ref and button elements我试图让我的按钮可点击,所以我有一个使用 h ref 和 button 元素的网站链接
【发布时间】:2019-07-03 05:55:17
【问题描述】:

我希望我的按钮链接到我创建的实际网站:例如 Joeys Auto

我的作品集网站是:http://loriroberg.com/cssfinalproject/index.html#home 它有一个 JOEYS AUTO 按钮。 Joeys Auto 的网站是http://loriroberg.com/final/index.html

如何更改此代码:

<div class="w3-col m3"><button class="button4 w3-button w3-padding-large w3-light-grey" style="margin-top:64px">Joeys Auto</button></div>

这样它会链接到 JOEYS AUTO?

以下代码位于我的作品集的 MY PROJECTS 部分。

<h3 class="w3-center">MY PROJECTS</h3>

<p class="w3-center"><em>Here are some of the projects I completed.<br />
I will post more soon.<br />
Click on the links to view them on the web.</em></p>
<br />
<!-- Responsive Grid. Four columns on tablets, laptops and desktops. Will stack on mobile devices/small screens (100% width) -->
<div class="w3-row-padding w3-center">


<div class="w3-col m3"><button class="button4 w3-button w3-padding-large w3-light-grey" style="margin-top:64px">Joeys Auto</button></div>

<div class="w3-col m3"><button class="button4 w3-button w3-padding-large w3-light-grey" style="margin-top:64px">CSS3 2D Animation</button></div>


<div class="w3-col m3"><button class="button4 w3-button w3-padding-large w3-light-grey" style="margin-top:64px">CSS3 Animation</button></div>

<div class="w3-col m3"><button class="button4 w3-button w3-padding-large w3-light-grey" style="margin-top:64px">CSS3 3D Animation</button></div>
<!--<button class="w3-button w3-padding-large w3-light-grey" style="margin-top:64px">LOAD MORE</button>  

【问题讨论】:

    标签: html button hyperlink href


    【解决方案1】:

    要链接到其他网站(例如,从您的作品集中链接到外部网站),您需要使用 HTML anchor tags。 您可以使用以下链接:

    <a href="http://example.com">Joey's Auto</a>
    

    如果您已经在 loriroberg.com,您也可以使用相对 URL:

    <a href="/final/index.html">Joey's Auto</a>
    

    这会将您带到http://loriroberg.com/final/index.html。 您可以在 this StackOverflow question 中找到有关相对 URL 与绝对 URL 的更多信息

    【讨论】:

    • 我应该更清楚。您应该使用锚标记 (&lt;a&gt;) 而不是 按钮标记进行导航。如果您想让锚标记看起来像按钮,您可以使用 CSS 或 style 属性(您正在使用的 style="margin-top:64px")设置它们的样式。你会想要摆脱所有按钮标签,只使用我在答案中列出的锚标签。
    • 感谢您的帮助。我会接受你的建议,因为它有效。谢谢。
    • 如果这解决了您的问题,那么您介意将其作为公认的答案吗?我的答案旁边应该有一个复选标记,您可以点击接受它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2016-03-31
    相关资源
    最近更新 更多