html - 图像作为按钮

标签 html css

我正在处理 HTML 页面,我想使用图像作为按钮。我的问题是它以灰色显示按钮,我想用作背景的图像较小,整个按钮位于另一个位置。我链接了两张图片,第一张显示了它应该是什么样子,第二张是我设法做到的。

你能帮我看看哪里出了问题吗(我是初学者,很抱歉,如果这是一个非常简单的问题并且解决方案很容易......)?

HTML 中的代码是:

<button type="image" name="in_cart">
    <img src="pic/in_cart.png">
</button>

有了这个图像 - 没有让它像按钮一样 - 处于正确的位置,但作为按钮它显示第二个图像中的状态

CSS:

#in_cart {
   position:absolute;
   top:165px;
   left:600px;
   width: 300px;
   height: 35px;
}

最佳答案

您可以在您的 css 文件中使用背景图片:

button{
  height:300px;
  width:200px;
  background-image: url(https://placekitten.com/g/200/300);
  background-repeat: no-repeat;
  color:red;
  }
<button>I'm a button!!!!</button>


海事组织:

我会创建一个 <a>元素,并相应地设置样式(而不是使用图像,使用 css 来“创建”您的图像):

a{
  
  height:100px;
  width:200px;
  background:black;
  padding:10px;
  border-radius:20%;
  color:gold;
  text-decoration:none; 
  font-family:times;
  }
<a href="#">I'm your styled link</a>

关于html - 图像作为按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27742288/

相关文章:

html - 液体布局中水平对齐的 div - 一个的背景延伸到另一个的后面

jquery - 使用 jQuery 和 AJAX 交换 Div 内容和 CSS

javascript - 图表.js 2.0 : How to change title of tooltip

javascript - 如何在我的 html 循环中制作带有彩虹颜色的按钮?

html - Facebook 评论插件暗模式不起作用

jquery - Twitter Bootstrap : Navbar input fields to wide in responsive mode

html - 为什么当我应用位置 :fixed to the body? 时窗口不会跳转或滚动

css - 如何使用 javascript 进行 3d 悬停?

html - 如果使用 DOCTYPE,则 Css 样式应用不正确

javascript - 猫头鹰旋转木马销毁问题(未捕获的类型错误 : Cannot read property 'destroy' of undefined )