简体   繁体   English

如何使按钮链接到页面?

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

I am newbie with Rails and Bulma and trying to create a button which can link to another page.我是 Rails 和 Bulma 的新手,并试图创建一个可以链接到另一个页面的按钮。 I mean, for example a button named facebook, will link to facebook page, a button named twitter will link to twitter. I mean, for example a button named facebook, will link to facebook page, a button named twitter will link to twitter.

And here is my code.这是我的代码。

<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>

My problem is, I thought that this line will link to the page twitter <a href="https://twitter.com/home?lang=en"></a> , but actually it does not work.我的问题是,我以为这条线会链接到页面 twitter <a href="https://twitter.com/home?lang=en"></a> ,但实际上它不起作用。 I tried some way but do not find any.我尝试了一些方法,但没有找到任何方法。

Could you guys please give me some ideas?大家能给我一些想法吗? Thank you very much.非常感谢。

As the comments state above, you are misusing buttons and links here.正如上面的评论 state 一样,您在这里误用了按钮和链接。 Try to keep your links as things that load new pages and buttons as things that submit forms and cause JS events.尽量保持你的链接作为加载新页面和按钮的东西,作为提交 forms 并导致 JS 事件的东西。

Most CSS frameworks will allow you to use styling for links and buttons the same way, so your end users will not notice the difference.大多数 CSS 框架将允许您以相同的方式对链接和按钮使用样式,因此您的最终用户不会注意到差异。

If you want a link, you would normally do something like:如果你想要一个链接,你通常会做这样的事情:

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

But if you want to add a little more to the link, like put an icon (or even a div) in it, just turn the link into a block:但是,如果您想在链接中添加更多内容,例如在其中放置一个图标(甚至是 div),只需将链接变成一个块:

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

For your example, this would look something like:对于您的示例,这看起来像:

<%= 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 %>

You are going to code a link, but your users will see a button.您将编写一个链接,但您的用户会看到一个按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM