我知道有手动选项,例如: How do you make the entire DIV clickable to go to another page? 但是,在Rails 3中,我们创建了这样的链接: %= link_to“name”,url% 我想知道 – 是否有一个正确的Rails方式来使
但是,在Rails 3中,我们创建了这样的链接:
<%= link_to“name”,url%>
我想知道 – 是否有一个正确的Rails方式来使整个div成为一个按钮.我意识到我可以做一个按钮.但是,假设我想用文本和图片等内容填充它 – 那么我将如何以轨道方式使整个div可点击?
例如:
<%= @ story.title%>
<%= @ story.blurb%>
在这个例子中,我想让#story可点击,轨道生成我指定的内容..任何想法?
对于那些感兴趣的人,答案是:<div class="class_name"> <%= link_to content_tag(:span, "Text for the LInk"), route %> </div>
然后,在CSS中将.class_name设置为position:relative;和:
.class_name span { width:100%; height:100%; position:absolute; z-index:2; top:0px; left:0px; }
该链接现在将采用其父容器的大小,从而给出整个容器是链接的印象.