如何将按钮的背景图像设置为左对齐?

时间:2016-05-03 10:37:17

标签: html css

如何让背景图像显示在按钮的左边框附近?



.button1 {
  background-color: transparent;
  background-image: url('nebifat.png') no-repeat;
  font-size: 30px;
  padding-left: 64px;
  text-align: left;
  position: relative;
  border-style: none;
  height: 7%;
  width: 50%;
  vertical-align: middle;
  margin-top: 10%;
  opacity: 0.6;
}

<center>
  <button id='r1' class='button1'>Matematica si Fizica</button>
</center>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您在no-repeat中设置background-image,而您可以使用background: url('...') no-repeatbackground-repeat: no-repeat,同时center已从网络标准中移除。您可以使用background-position

定位背景

.button1 {
  background-color: transparent;
  background-image: url("http://placehold.it/50x50");
  background-repeat: no-repeat;
  font-size: 30px;
  padding-left: 64px;
  text-align: left;
  position: relative;
  border-style: none;
  height: 7%;
  width: 50%;
  vertical-align: middle;
  margin-top: 10%;
  opacity: 0.6;
  border: 1px solid black;
  background-position: left;
}
<button id='r1' class='button1'>Matematica si Fizica</button>