2014-06-17 105 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>