HTML 中按钮内的图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4101977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:07:41  来源:igfitidea点击:

Icon inside button in HTML

html

提问by Damir

I need to put small icon inside button in HTML (for example I need to have facebook button on my site, inside button first F icon and then "facebook"). How to do that ?

我需要在 HTML 中的按钮内放置小图标(例如,我需要在我的网站上有 facebook 按钮,按钮内首先是 F 图标,然后是“facebook”)。怎么做 ?

回答by Quentin

<button><img src="facebook.png" alt=""> Facebook</button>

回答by Alec

.facebook-button {
  background: url('https://2.bp.blogspot.com/-lFFvYHv-Z8w/WAOFS0P5FdI/AAAAAAAAF68/Aiv0D5NkUKIbL3_6G42LZm1iQ6co1tmgACLcB/s320/facebook-16px.png') left center no-repeat;
  padding-left: 15px;
}
<!DOCTYPE html>
<html>

<body>
<input type="button" class="facebook-button" value=" Facebook" />
</body>
</html>

回答by user3677801

Add the following data using the path name for the image

使用图像的路径名添加以下数据

 <img src="images/facebook-logo.png"/> 

Add the width and height attributes if you want to resize the icon

如果要调整图标大小,请添加宽度和高度属性

 <img src="images/facebook-logo.png" width="75" height="75"/>