Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add svg icon to a button with a text

I have a source of the svg icon svgIcon. I need to add this icon to the button. It would look very similar to this

enter image description here

I tried this:

css

  .btn {
     border: none;
     color: grey;
     padding: 12px 16px;
     font-size: 16px;
     cursor: pointer;
     background-image: url("http://alexfeds.com/wp- 
     content/uploads/2018/04/save_icon.svg");
     background-repeat: repeat-y;
       }

   <button class="btn"> Save</button>

But result is this: enter image description here

How to have the svg icon inside the button and text description beside it?

like image 441
AlexFF1 Avatar asked Dec 11 '22 06:12

AlexFF1


2 Answers

I usually use the pseudo element. Please check the result below:

.btn {
     border: none;
     color: grey;
     padding: 12px 16px;
     font-size: 16px;
     cursor: pointer;
 }
 
 .btn:before {
   content: url(http://alexfeds.com/wp-content/uploads/2018/04/save_icon.svg);
   width: 20px;
   float: left;
   margin-right: 5px;
   margin-top: -2px;
 }
<button class="btn">Save</button>
like image 148
hoangkianh Avatar answered Dec 20 '22 14:12

hoangkianh


Try to increase padding-left and set background-size of the icon. There is no need of background-repeat to repeat-y, use no-repeat instead.

.btn {
     border: none;
     color: grey;
     padding: 12px 16px 12px 36px; // Changed padding-left value, set as per your requirement
     font-size: 16px;
     cursor: pointer;
     background-image: url("http://alexfeds.com/wp- 
     content/uploads/2018/04/save_icon.svg");
     background-size: 25px auto; //Set as per your requirement
     background-repeat: no-repeat; // Changed
 } 
like image 42
Zuber Avatar answered Dec 20 '22 12:12

Zuber