字体awesome图标按钮,标签在下方

3
我需要创建一个带有字体awesome图标和一个在该图标下面的文本的按钮,用于导航菜单。结果应该看起来像MS Ribbon中的图标: enter image description here 我还需要该按钮下面的箭头(例如,“新建”按钮)以获取更多选项... 这是我将如何创建按钮: JSFiddle: http://jsfiddle.net/3GMjp/77/

.my-fancy-container {
  display: inline-block;
  border: 1px solid #ccc;
  border-radius: 6px;
  margin: 60px;
  padding: 10px;
}
.my-text {
  font-family: "Courier-new";
}
.my-icon {
  vertical-align: middle;
  font-size: 40px;
}
<div class="my-fancy-container">
  <span class='icon icon-file-text my-icon'></span>
  <span class="my-text">New</span>
</div>

3个回答

4
要将文本放置在按钮下方,添加display: block:
.my-text {
  display: block;
  font-family: "Courier-new";
}

为了把你的图片居中,可以添加一个 text-align 属性:
.my-fancy-container {
  border: 1px solid #ccc;
  border-radius: 6px;
  display: inline-block;
  margin: 60px;
  padding: 10px;
  text-align: center;
}

对于箭头,请添加一个 div 元素,并使用以下 CSS 样式:
<div class="arrow-down"></div>

CSS:

.arrow-down {
    width: 0; 
    height: 0; 
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid black;
    margin: 0 auto;
}

JSfiddle: http://jsfiddle.net/ghorg12110/3GMjp/418/

片段:

.my-fancy-container {
  border: 1px solid #ccc;
  border-radius: 6px;
  display: inline-block;
  margin: 60px;
  padding: 10px;
  text-align: center;
}

.my-text {
  display: block;
  font-family: "Courier-new";
}

.my-icon {
    vertical-align: middle;
    font-size: 40px;
}

.arrow-down {
 width: 0; 
 height: 0; 
 border-left: 5px solid transparent;
 border-right: 5px solid transparent;
 border-top: 5px solid black;
    margin: 0 auto;
}
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet"/>
<div class="my-fancy-container">
    <span class='icon icon-file-text my-icon'></span>
    <span class="my-text">Hello World</span>
    <div class="arrow-down"></div>
</div>


3

display: blocktext-align: center添加到您的图标类中。

Fiddle


0
另一种可能性是使用beforeafter选择器。

查看这个fiddle

正如您在CSS中所看到的那样

 .my-fancy-container {
        display: inline-block;
        border: 1px solid #ccc;
        border-radius: 6px;
        margin: 60px;
        padding: 30px;
        position: relative;
    }
    
    .my-fancy-container::after {
        content: "\f0d7";
        font-family: FontAwesome;
        font-style: normal;
        font-weight: normal;
        text-decoration: inherit;
    /*--adjust as necessary--*/
        color: #000;
        font-size: 18px;
        padding-right: 0.5em;
        position: absolute;
        bottom: 5px;
        left: 45%;
    }
    
    .my-text {
        font-family: "Courier-new";
    }
    
    .my-fancy-container::before {
        content: "\f15c";
        font-family: FontAwesome;
        font-style: normal;
        font-weight: normal;
        text-decoration: inherit;
    /*--adjust as necessary--*/
        color: #000;
        font-size: 28px;
        padding-right: 0.5em;
        position: absolute;
        top: 5px;
        left: 40%;
    }
    
    .my-icon {
        vertical-align: middle;
        font-size: 40px;
    }
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet"/>

<div class="my-fancy-container">
    <span class="my-text">Hello World</span>
</div>

只有一些小改动 :)

当然,你也可以使用 before 选择器来放置图片... 这样你就可以在按钮上放置两张图片和中间的文本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接