Everything should be stated as simple as possible, but not simpler.A. Einstein
<div class="bl_button__wrapp"> <div class="bl_button"> <i class="fa fa-bars" aria-hidden="true"></i> <span class="bl_button__text">menu</span> </div> </div>
.bl_button__wrapp{ width: 100%; margin: 5% auto; font-size: 30px; line-height: 34px; color: blue } .bl_button{ position: relative; width: 150px; padding: 10px; margin: 0 auto; text-align: center; border: 1px solid #00f; cursor:pointer; } .fa-bars{ position: absolute; left: 10px; font-size: 34px; } .bl_button__text{ display: inline-block; }
See the Pen badge by Andry Zirka ( @ BlackStar1991 ) on CodePen .
This is the standard description of the button. I myself have been writing my code like this for a long time. This writing is especially practiced by those who use ready-made icon fonts like FontAwesome
Some difficulties arise if the text should be centered, and the icon is slightly offset from the text. But all this is perfectly solved through the property position: absolute; set by the icon. There are also problems with the positioning of this icon with the adaptability of the button, but this is another story.
Now I would like to describe my method of creating icons in the text of the page (using the example of the same FontAwesome).
HTML
<button class="button_menu"> <span class="button_menu__text button_icon__menu">menu</span> </button> <button class="button_menu"> <span class="button_menu__text button_icon__menu"> .</span> </button>
.button_menu{ min-width: 280px; margin-top: 5%; margin-left: 4%; font-size: 4em; color: blue; border: 1px solid #00f; outline:none; /* */ background:none; /* */ } .button_menu__text{ position:relative; width: 100%; display: inline-block; text-align: center; margin: 0 auto; padding: 10px 40px; } .button_icon__menu:before{ content: "\f0c9"; font-family: FontAwesome; position: absolute; left: 0px; top: 14px; }
Andry Zirka ( @ BlackStar1991 ) on CodePen .
button
tag, you often have to drop or redefine styles, otherwise it doesn't look good. outline:none; background:none; border:none;
<button class="button_menu"> <span class="button_menu__text button_icon button_icon__menu button_icon__menu_active">menu</span> </button>
Source: https://habr.com/ru/post/335632/
All Articles