2014-06-17 48 views
1

我有下面的代碼,其中有文字按鈕, 我想添加到按鈕也從引導圖標(在文本的左側)我應該怎麼做?將引導圖標添加到按鈕

的圖標是glyphicon glyphicon加

<div style="margin-top: 20px"> 
    <p> 
     @Html.ActionLink("New", "Create", 
     null new { @class = "Button", @style = "float:right" }) 
    </p>  
</div> 
<br /> 
<style type="text/css"> 
     .CreateButton { 
      background: blue 
; 
      color: white; 
      padding: 4px 10px 4px 10px; 
      height: 30px; 
      width: 60px; 
     } 


    </style> 
<br /> 
+6

這看起來不是很完整。代碼頂部的這個類是什麼? –

+0

@ StenPelzer -I've更新帖子請檢查並讓我知道如果有些遺漏... –

+0

您發佈的代碼不是html。它是什麼? – tjati

回答

1

您發佈並沒有真正讓我來幫助你更好,但是我們可以嘗試的代碼。

您需要將.glyphicon類的所有屬性複製到.CreateButton:before {}之內並添加 - 還有 - content屬性,其中包含要插入圖標的值。檢查glyphicons stylsheet找出你想要的圖標的代碼。您正在搜索的加號具有「\ 2b」的值。

.CreateButton:before { 
    // the part that will be different for each icon 
    content: "\e001"; 
    // copied from .glyphicon class 
    position: relative; 
    top: 1px; 
    display: inline-block; 
    font-family: 'Glyphicons Halflings'; 
    font-style: normal; 
    font-weight: 400; 
    line-height: 1; 
    -webkit-font-smoothing: antialiased; 
} 

由於這是公認的答案,我會補充說,在某些情況下,它可能是更好的用戶緩存使用的答案。

+0

非常感謝,你如何獲得內容:「\ e001」;我應該如何放置glyphicon glyphicon-plus? –

+0

查看最新的答案 –

3

使用這種插入圖標

<i class="glyphicon glyphicon-plus"></i> 

UPDATE: 通過使用標籤,你會被自動插入HTML格式的圖標。欲瞭解更多信息,請看這GLYPHICONS - bootstrap icon font hex value。也最好使用這些類。

2

您可以使用一個按鍵標籤,而不是輸入

<button type="submit" class="btn btn-primary"> 
    <i class="icon-user icon-white"></i> Sign in 
</button>