html - 在键入 ="image"的输入中隐藏标题文本

标签 html css

我想使用图像类型的输入,当悬停在上面时也有标题文本显示。但是,此文本始终显示在图像“后面”。

我这样定义我的图像:

.left {
  background-image: url("http://uxrepo.com/static/icon-sets/flat-arrows/png32/64/000000/flat-circle-chevron-left-arrow-64-000000.png");
}
<input type="image" class="left" id="mToggle" width="64" height="64" value=" " title="new toggle button"/>

CSS 类的原因是因为我在点击时切换图像。这是一个JSFiddle .

旁注:我发现问题只出现在 Chrome 中。它不会出现在 IE 或 Firefox 中。

最佳答案

<input/> :

type="image": A graphical submit button. You must use the src attribute to define the source of the image and the alt attribute to define alternative text. You can use the height and width attributes to define the size of the image in pixels.

(强调我的)

因此,您的 HTML 无效。您需要让按钮看起来像下面的代码片段。

如果您已经切换了 class onclick对于 JavaScript,我建议您放弃 CSS 规则,而是更改图像 src直接地。您是否使切换依赖于 class , altsrc属性,是你的选择。

document.getElementById('mToggle').addEventListener('click',function(){
  if(this.className=='left'){
    this.src='http://uxrepo.com/static/icon-sets/flat-arrows/png32/64/000000/flat-circle-chevron-right-arrow-64-000000.png';
    this.alt='→';
    this.className='right';
  }
  else{
    this.src='http://uxrepo.com/static/icon-sets/flat-arrows/png32/64/000000/flat-circle-chevron-left-arrow-64-000000.png';
    this.alt='←';
    this.className='left';
  }
});
<input id="mToggle" class="left" type="image" width="64" height="64"
  src="http://uxrepo.com/static/icon-sets/flat-arrows/png32/64/000000/flat-circle-chevron-left-arrow-64-000000.png"
  alt="←" value=" " title="new toggle button"/>

(使用上面的 JS 代码或任何等效的 jQuery。)

关于html - 在键入 ="image"的输入中隐藏标题文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31863063/

相关文章:

css - CSS 中的像素密度、视网膜显示和字体大小

html - 如何让图片向下滑动

HTML 无序列表在下方移动一行

javascript - 在本地保存 JSON 文件

javascript - 为什么将 AngularJS 指令限制为类是不好的?

jquery - 如何在单击文档正文和指定元素时淡入和淡出任何元素?

html - 具有滚动内容的垂直居中未知高度 div

javascript - 在我的 Carousel Slider 的左侧和右侧获得灰色。怎样去除灰色?

html - 如何验证文本区域中的模式匹配?

html - CSS :first-letter text-indent not working