简体   繁体   English

在按钮文本上方显示 Font Awesome 图标

[英]Displaying Font Awesome icon above button text

I need a button to look like the button in the image:我需要一个看起来像图像中的按钮的按钮:

When I add the fontawesome icon to the button it shows, but I'd like it to display on top of the text if that's possible?当我将 fontawesome 图标添加到它显示的按钮时,但如果可能的话,我希望它显示在文本之上吗?

 .button-examples { background-color: #0C3E7e; margin-top: 50px; height: 130px; border-radius: 15px 15px 15px 15px; margin-left: 10px; font-weight: 600; }
 <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <button class="button-examples"> <i class="fa fa-users" aria-hidden="true"></i> See client examples </button>

按钮

Add添加

.button-examples i {
  display: block;
}

to force a line-break between the icon and the text.强制在图标和文本之间换行。 See: https://jsfiddle.net/9b5304ps/请参阅: https ://jsfiddle.net/9b5304ps/

Just add <br/> like this,只需像这样添加<br/>

<button class = "button-examples">
    <i class="fa fa-users" aria-hidden="true"></i><br/>
    See client examples
</button>

OR, simple make you icon as block level element或者,简单地让你的图标成为块级元素

.button-examples i{
      display:block;
}

Demo演示

You can do it like this:你可以这样做:

https://jsfiddle.net/9ahf4ymg/ https://jsfiddle.net/9ahf4ymg/

<button class = "button-examples">
    <i class="fa fa-users icon" aria-hidden="true"></i>
    <p>
      See client examples
    </p>
</button>

And css和CSS

.icon{
  font-size: 48px;
  color: white;
}
.button-examples{
    background-color:#0C3E7e;
    margin-top:50px;
    height:130px;
    border-radius: 15px 15px 15px 15px;
    margin-left:10px;
    font-weight:600;
    color: white;
}

You can useflex-direction: column in .button-examples like so:您可以像这样在.button-examples中使用flex-direction: column

 .button-examples { display: flex; /* The direction in which lines of text are stacked */ flex-direction: column; align-items: center; background-color: #0C3E7e; padding: 8px; border-radius: 15px; font-weight: 600; color: white; width: 100px; }.button-examples p { font-size: .8rem; margin: 0 auto; }
 <link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet" crossorigin="anonymous"> <button class="button-examples"> <i class="fas fa-users fa-3x" aria-hidden="true"></i> <p>See client examples</p> </button>

Wrap the text in a block element ( <p> , <div> , etc).将文本包装在块元素( <p><div>等)中。 Details commented in HTML\CSS. HTML\CSS 中注释的详细信息。

 .button { background-color: #0C3E7e; margin-top: 50px; margin-left: 10px; padding: 10px; /* Center icon and text */ width: 130px; /* Needs width defined */ height: 130px; border-radius: 15px; /* One value for four identical sizes*/ font-weight: 600; color: #fff; /* As per screenshot */ } /* A block element (<p>) is wrapped around text in order to place it under the icon and allow it to have a different font-size than the icon */.button p { font-size: 1rem; margin: 0 auto; }
 <link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet" crossorigin="anonymous"> <button class="button"> <.--.fa-3x makes icon 3 times the regular size--> <i class="fas fa-users fa-3x" aria-hidden="true"></i> <p>See client examples</p> </button>

You can use the code below.

HTML code:
    <button class = "button-examples">
      <i class="fa fa-users" aria-hidden="true"></i>
      See client examples
    </button>

CSS code: 
   .button-examples {
    margin: 0 auto;
    height: 110px;
    width: 110px;
    border-radius: 15px;
    border: none;
    background: #0C3E7e;
    color: #fff;
    text-align: center;
}
.button-examples i{
    font-size:45px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM