HTML中给Button加图片背景的具体写法

本文是搜集和整理的几种给HTMLButton 添加背景图片的方法:

写法一:写在HTML里面。缺点是图片不容易和按钮互相完美贴合,如果美观的话还需要进一步想想办法。

<button>

  <img src="../img.png" >按钮一

</button>

写法二:写在CSS中。这个就是把按钮的边框去掉了,把图像设置为不重复,其他的效果自己添加即可。

button{
    width: 100px;
    height:45px;
    background: url("vue1/test2.png") no-repeat;
    border-style: none;
}

写法三:内联CSS的写法。这种写法需要注意你的png图片的具体位置是相对于你的HTML文件的,我的图片是是放在css/images/目录下了。这种写法简单,直观,肯定起作用。缺点是难以重用。

<div class=bigButtonDiv id="idBigButtonDiv">
    <button  class="bigbutton" id="FirstBigButton"   style="background: url(css/images/CYD1_S.png) no-repeat;height: 120px;width:  120px;" aria-label="FirstBigButton"  title="FirstBigButton" >   </button>     
    <button  class="bigbutton" id="SecondBigButton"  style="background: url(css/images/CYD2_S.png) no-repeat;height: 120px;width:  120px;" aria-label="SecondBigButton" title="SecondBigButton">   </button>
    <button  class="bigbutton" id="ThirdBigButton"   style="background: url(css/images/CYD3_S.png) no-repeat;height: 120px;width:  120px;" aria-label="ThirdBigButton"  title="ThirdBigButton" >   </button>     
    
  </div>

后续也许会给更多的写法吧,目前就总结到这里,写给自己看,怕自己忘却。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值