簡體   English   中英

如何使按鈕鏈接到頁面?

[英]how can I make a button link to a page?

我是 Rails 和 Bulma 的新手,並試圖創建一個可以鏈接到另一個頁面的按鈕。 I mean, for example a button named facebook, will link to facebook page, a button named twitter will link to twitter.

這是我的代碼。

<div class="field">
 <p class="control">
 <button class="button is-primary is-outlined is-fullwidth">
 <span class="icon">
 <i class="fab fa-twitter"></i>
 </span>
 <span>twitter</span>
 <a href="https://twitter.com/home?lang=en"></a>
 </button>
 </p>
 </div>

我的問題是,我以為這條線會鏈接到頁面 twitter <a href="https://twitter.com/home?lang=en"></a> ,但實際上它不起作用。 我嘗試了一些方法,但沒有找到任何方法。

大家能給我一些想法嗎? 非常感謝。

正如上面的評論 state 一樣,您在這里誤用了按鈕和鏈接。 盡量保持你的鏈接作為加載新頁面和按鈕的東西,作為提交 forms 並導致 JS 事件的東西。

大多數 CSS 框架將允許您以相同的方式對鏈接和按鈕使用樣式,因此您的最終用戶不會注意到差異。

如果你想要一個鏈接,你通常會做這樣的事情:

<%= link_to "Link Title", "url-or-path", class: "some-class"

但是,如果您想在鏈接中添加更多內容,例如在其中放置一個圖標(甚至是 div),只需將鏈接變成一個塊:

<%= link_to "url-or-path", class: "some-class" do %>
  <i class="icon-class"></i>
  Link Title
<% end %>

對於您的示例,這看起來像:

<%= link_to "https://twitter.com/home?lang=en", class: "button is-primary is-outlined is-fullwidth" do %>
  <i class="fab fa-twitter"></i>
  Twitter
<% end %>

您將編寫一個鏈接,但您的用戶會看到一個按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM