user3142695
user3142695

Reputation: 17332

Font awesome icon button with label below

I need to create a button with a font awesome icon and a text below that icon for a navigation menu. The result should look like i.e. the icons in the MS ribbon:

enter image description here

I also need the arrow below of that (ie. "new"-button) for more options...

This is how I would create the button:

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>

Upvotes: 3

Views: 18858

Answers (3)

Dwza
Dwza

Reputation: 6565

A nother possibility is to use the before and after selector

See this fiddle

As you can see in your 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>

there are only a few changes :)

Of course you can place the image with the before selector as well.. so you have two images on the button and the text in the middle.

Upvotes: 0

Goombah
Goombah

Reputation: 2855

Add display: block and text-align: center to your icon class.

Fiddle

Upvotes: 3

Magicprog.fr
Magicprog.fr

Reputation: 4100

To place the text bellow the button, add display: block:

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

To center your image, add a text-align:

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

For the arrow, add a div and this 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/

SNIPPET :

.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>

Upvotes: 4

Related Questions