html - 如何使 float 链接可点击整行?

标签 html css css-float

CodePen 在这里:http://codepen.io/anon/pen/BKVMoY

ul {
  width: 40%;
  border: 1px solid black;
  list-style: none;
  padding: 0;
}
span:last-of-type {
  float: right;
}
<ul>
  <li>
    <a href="#">
      <span>New York</span>
      <span>$489</span>
    </a>
  </li>
  <li>
    <a href="#">
      <span>New York</span>
      <span>$489</span>
    </a>
  </li>
  <li>
    <span>New York</span>
    <span>$489</span>
  </li>
  <li>
    <span>New York</span>
    <span>$489</span>
  </li>
</ul>

为什么 float 元素没有下划线?

如何让它在 span 之间的空间可点击?

最佳答案

为什么 float 元素没有下划线?

16.3.1 Underlining, overlining, striking, and blinking: the ' text-decoration ' property

Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.

要解决这个问题,您可以设置 text-decoration: inherit在 float 跨度上。

span:last-of-type {
  float: right;
  text-decoration: inherit;
}

如何让它在跨度之间的空间可点击?

您可以设置 <a>display:block ,它将占据整个可用宽度。

a {
  display: block;
}

ul {
  width: 40%;
  border: 1px solid black;
  list-style: none;
  padding: 0;
}
a {
  display: block;
}
span:last-of-type {
  float: right;
  text-decoration: inherit;
}
<ul>
  <li>
    <a href="#">
      <span>New York</span>
      <span>$489</span>
    </a>
  </li>
  <li>
    <a href="#">
      <span>New York</span>
      <span>$489</span>
    </a>
  </li>
  <li>
    <span>New York</span>
    <span>$489</span>
  </li>
  <li>
    <span>New York</span>
    <span>$489</span>
  </li>
</ul>

关于html - 如何使 float 链接可点击整行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36756330/

相关文章:

html - 是否可以通过编程方式获取网页的生成源?

javascript - 如何限制在线考试期间使用其他应用程序?

html - 无法悬停在 img 元素上,当 img 悬停时无法旋转元素

css - 如果我们将 textAlign 设置为 "right"用于 spark textinput 控件,文本会在左侧溢出吗?

html - 将 3 个 div 并排放置

javascript - 无法弄清楚为什么 javascript 在我的 php 文件中不起作用

html - Firefox 中无法选择的滚动条

css - 响应 float 问题

html - 为什么 'clear:left' 也正确清除?

css - div 中 div 的溢出行,滚动不是换行