简体   繁体   English

Firefox忽略输入type =“ image”上的宽度和高度

[英]Firefox ignores width and height on the input type=“image”

I create the image button. 我创建图像按钮。 The button should change on hover. 悬停时该按钮应更改。 I set the image with CSS, so there is no need to use src attribute in my code. 我使用CSS设置了图像,因此无需在代码中使用src属性。 Chrome, Safari works well, but Firefox 48 completely ignores sizes of the input. Chrome,Safari运行良好,但是Firefox 48完全忽略了输入的大小。 I tried both CSS and HTML way. 我尝试了CSS和HTML的方式。 Is it a bug? 是虫子吗? What is the correct way? 正确的方法是什么?

Fiddle: https://jsfiddle.net/nyppzpqx/5/ 小提琴: https : //jsfiddle.net/nyppzpqx/5/

Here is the view in firefox 48: 这是Firefox 48中的视图:

Firefox 48 OS X 10.10

If you add display: block to the .btn-pay element, it works just fine. 如果将display: block添加到.btn-pay元素,则可以正常工作。 It may be something with custom browser styles. 可能是自定义浏览器样式的东西。

Altough as Turnip said, it is better to avoid using img element without src attribute. 正如Turnip所说,最好避免使用没有src属性的img元素。

You can always restructure the way the html is written. 您始终可以重组html的编写方式。 This way you do not need the src attribute. 这样,您不需要src属性。 The size is given to the outer div, and then the button is positioned on top of it with an image that spans the entire div: 将大小指定给外部div,然后将按钮放置在其顶部,并带有覆盖整个div的图像:

<div class="btn-pay">
   <input type="button" name="kind" value="test" class="btn-pay-input" >
</div>

and then update the styling: 然后更新样式:

.btn-pay {
  width:135px;
  height: 60px;
}
.btn-pay-input {
  background: url(http://placehold.it/135x60);
  color: transparent;
  transition: all 0.3s;
  width:100%;
  height:100%;
  text-align:center;
}
.btn-pay-input:hover {
  background: url(http://placehold.it/135x60/fff000);
}

Here is the fiddle 这是小提琴

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

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