2014-08-28 70 views
-4

我想更改erb模板中「Explore」和「Submit Your project」按鈕的顏色。目前它們是藍色的。如果Shoud我使用div要做到這一點,還是有其他方式太如何更改.erb模板中鏈接按鈕的顏色

<div id="header"> 
    <%= link_to 'Explore', explore_path %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <%= link_to 'Submit Your Project', submit_path %> 

     <div class="wrapper clearfix"> 
     <h1 id="lockitron_header"><a href="/"><%= Settings.product_name %></a></h1> 
     </div> 
    </div> 
+0

這些' '是怎麼回事?是否爲元素添加了額外的寬度?因爲這就是css的用途。 – 2014-08-28 14:06:49

+1

你需要編寫css樣式表。它不是在軌道問題上的紅寶石。 – emj365 2014-08-28 14:07:14

+0

Max Williams:是創造空間。是否有替代方案? – Programmer345 2014-08-28 14:16:47

回答

1

使用style內聯CSS

<%= link_to 'Explore', explore_path, style: "color: red;" %> 

或使用class

<%= link_to 'Explore', explore_path, class: "link-color" %> 

,並在樣式表

.link-color{ 
    color: "red"; 
} 
+3

通過類和相應的樣式表做更好。在需要數據驅動樣式時保存樣式標籤。 – 2014-08-28 14:08:08

+0

@MaxWilliams是的,我現在編輯了答案,它告訴我們如何根據需要使用兩者。 – RSB 2014-08-28 14:15:39

2

只要給class和id到您的錨,然後用CSS來給他們不同的顏色

<%= link_to 'Explore', explore_path, class: "black" %> 
<%= link_to 'Submit Your Project', submit_path, class: "black" %> 

而且在CSS

.black {color: #000;} 

這是非常基本的CSS和HTML您應該結賬CSSHTML