简体   繁体   English

图像按钮上图像和边框之间的空白

[英]White space between image and border on image button

I am getting some white space between my image and the button border.我的图像和按钮边框之间有一些空白。 I cant seem to get rid of it whatever i try.无论我尝试什么,我似乎都无法摆脱它。

 #rock_button { outline: none; position: absolute; top: 265px; left: 19%; border-radius: 8px; cursor: hand; text-align: center; border-color: #3f441c; display: block; padding: none; box-shadow: 2px 10px 10px 5px black }
 <button id="rock_button" class="slideRight" name="choice" value="rock"> <img src="http://i.imgur.com/XT41ZXk.jpg" alt="Rock"> </button>

Any help would be great.任何帮助都会很棒。 Im using sinatra and ruby with my html if that makes a difference?如果这有区别,我将 sinatra 和 ruby​​ 与我的 html 一起使用?

padding: none should be padding: 0; padding: none应该是padding: 0;

You also need to remove the default spacing around the img by using display: block ( further reading ).您还需要使用display: block进一步阅读)删除img周围的默认间距。

 #rock_button { outline: none; /*position: absolute; top: 265px; left: 19%;*/ border-radius: 8px; cursor: hand; text-align: center; border-color: #3f441c; display: block; padding: 0; box-shadow: 2px 10px 10px 5px black } img { display: block; }
 <button id="rock_button" class="slideRight" name="choice" value="rock"> <img src="http://i.imgur.com/XT41ZXk.jpg" alt="Rock"> </button>

html: html:

<button id="rock_button" class="slideRight" name="choice" value="rock">
  <!--<img src="http://i.imgur.com/XT41ZXk.jpg" alt="Rock">-->
</button>

Add the backgorund using css background image url tag also change padding:0 to reset padding space in browser default使用 css 背景图片 url 标签添加 backgorund 也更改 padding:0 以重置浏览器默认的填充空间

css: css:

#rock_button {
width:50px;
height:50px;
  outline: none;
  position: absolute;
  top: 265px;
  left: 19%;
  border-radius: 8px;
  cursor: hand;
  text-align: center;
  border-color: #3f441c;
  display: block;
  padding: none;
  box-shadow:  2px 10px 10px 5px black
  background-image:url('http://i.imgur.com/XT41ZXk.jpg');
}

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

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