简体   繁体   English

Bootstrap:里面有图像的按钮,删除可见的按钮部分

[英]Bootstrap: button with image inside, remove visible button parts

I have the following html: 我有以下html:

<br/><br/><center>
  <button>
    <img src="https://www.abeautifulsite.net/uploads/2014/09/menu-icon.png?width=600&key=4bc015049071e7e16c61decfe5eca75cd081194e39a9e235b780ce644ef7e6ce"/>
  </button>
</center>

and css: 和css:

button  {
  width: 80px;
  height: 90px;
}

img  {
  width: 80px;
  height: 90px;
}

which results in this . 这导致了这一点 There are edges of the button visible. 按钮的边缘可见。 Is there a way to make them invisible/expand the image to all of the button? 有没有办法让它们不可见/将图像扩展到所有按钮?

You don't really need Bootstrap to do this. 你真的不需要Bootstrap来做这件事。 Here is a solution without: 这是一个没有的解决方案:

 button { padding: 0; border: 0; background: transparent; } img { display: block; width: 80px; height: 90px; } 
 <br/><br/><center> <button> <img src="https://www.abeautifulsite.net/uploads/2014/09/menu-icon.png?width=600&key=4bc015049071e7e16c61decfe5eca75cd081194e39a9e235b780ce644ef7e6ce"/> </button> </center> 

And here is a solution with the version 3 of Bootstrap you tried to include (URL in your codepen gives a 404), taken from their documentation : 这是一个解决方案,你试图包含的Bootstrap版本3(你的codepen中的URL给出了404),取自他们的文档

 @import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'); img { width: 80px; height: 90px; } 
 <br/><br/><center> <button class="btn btn-link"> <img src="https://www.abeautifulsite.net/uploads/2014/09/menu-icon.png?width=600&key=4bc015049071e7e16c61decfe5eca75cd081194e39a9e235b780ce644ef7e6ce"/> </button> </center> 

I would do it as: 我会这样做:

 button { width: 80px; height: 90px; padding: 0; border: none; } img { width: 100%; height: 100%; overflow: hidden; } 
 <br/><br/> <center> <button> <img src="https://www.abeautifulsite.net/uploads/2014/09/menu-icon.png?width=600&key=4bc015049071e7e16c61decfe5eca75cd081194e39a9e235b780ce644ef7e6ce"/> </button> </center> 

Add to your css the border property and set it to 0 border属性添加到css并将其设置为0

button {
  width: 80px;
  height: 90px;
  border: 0;
}

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

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