CSS:可点击的 Li(文本缩进链接)

标签 css

我在具有背景图像的列表项上有类。我想文本缩进 anchor 标记文本并使整个列表项可点击。我无法更改标记,具有背景的类需要应用于 li 而不是 a。谢谢!

<ul>
    <li> <a href="#">Link One </a></li>
    <li> <a href="#">Link Two </a></li>
</ul>

ul {
  list-style:none;
}
li {
  display: inline-block;
  text-indent: -999px;
  background-color: lime;
  width: 100px;
  height: 100px;
  margin-right: 10px;
}
li a {
  text-indent: -9900px;
  height: 100px;
  width: 100px;
}

最佳答案

试试这个

JSfiddle Demo

CSS

ul {
  list-style:none;
}

li {
  display: inline-block;
  background-color: lime;
  margin-right: 10px;
}

li a {
  text-indent: -9900px;
  height: 100px; /* let the size of the link determine the li size */
  width: 100px;
  display: block; /* this is the vital part */
}

关于CSS:可点击的 Li(文本缩进链接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25190780/

相关文章:

css - 制作梯形标签形状

css - 将 Lighten Css 特性嵌入到 Jsx/React

css - Scss - 将同级 css 应用于子元素

jquery - JSSOR宽屏幻灯片

jquery - 使用 jQuery 定位多个元素

html - 字体在 IE10 中不起作用

ruby-on-rails-3 - Rails 3.1 - 更改默认脚手架 View 和模板

CSS 过渡比例/不透明度悬停兼容性

javascript - 让 react 迟钝的网站尽可能容易地响应?

html - 如何在使用 webpack 时在 css 中加载字体?