html - 为 css 图像获取 alt 的解决方法

标签 html css accessibility attr-accessible

我开始知道我们不能为 css 生成的图像设置 alt。有一些解决方案说通过具有 title 属性 我们只能在悬停 在图像上,但是当我们禁用 css 时,我们将无法看到该文本代替图像。在我的情况下,即使 css 是,我也需要显示文本已禁用。是否有任何解决方法可以在禁用 css 时使文本可见。

    <span class="myimageclass">
    hi
    </span>
    <style>
    .myimageclass
    {
    height: 100px;
    width: 200px;

    background-image:url('http://cdn.osxdaily.com/wp- 
    content/uploads/2011/10/NSTexturedFullScreenBackgroundColor.png');
    color:red;
    overflow: hidden;
    text-indent: -9999px;



    }
    </style>

谢谢, 巴拉吉。

最佳答案

您可以使用 text-indentoverflow: hidden

这个方法不太灵活,希望你能用上。

.image {
  width: 200px;
  height: 100px;
  display: block; /* it needs for inline elements like span */
  background: url(http://cdn.osxdaily.com/wp-content/uploads/2011/10/NSTexturedFullScreenBackgroundColor.png);
  overflow: hidden;
  text-indent: -9999px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="image js-image">
  Image alt
</div>

<button class="js-button">On/Off styles</button>

<script>
  $('.js-button').click(function() {
    $('.js-image').toggleClass('image');
  });
</script>

关于html - 为 css 图像获取 alt 的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30636222/

相关文章:

html - 单击页面并向右拖动时显示水平溢出隐藏项

html - NVDA 在 Firefox 上从父级聚焦时不会读取第一个 HTML 子级

php - 嵌入在 html 中的 JavaScript 未加载

html - 自定义字体(字体)在发布时不起作用

html - 更改/修复导航栏上的字体

C++,Linux : how to limit function access to file system?

html - 如果元素被标签包裹,标签是否需要 "for"属性?

php - dl dd 的 xpath 查询不起作用

javascript - 为什么绝对定位的父项中的百分比宽度子项在 IE 中不起作用?

html - 水平滚动不显示右边距