css - 如何获取内联 block 元素内的文本以进行识别?

标签 css

简单地说,这里的复选框是图形化的,因为出于可访问性原因我不想使用复选框元素(只有链接应该响应交互)。

但是在 href 旁边设置一个 span 并让文本缩进以与文本的开头对齐似乎是一个相当大的挑战。 这是 Codepen :

ul { 
  padding: 0px;
  margin: 0px;
  width: 140px;
  background-color: #fffaaa;
  margin-bottom: 10px;
  list-style: none;
}

span.facetapi-check-active {
  background-image: url('https://www.drupal.org/files/project-images/Very-Basic-Checked-checkbox-icon.png');
  width: 15px;
  height: 15px;
  background-repeat: no-repeat;
  background-size: 15px 15px;
  display: inline-block;
}
<ul>
  <li>
    <span class="facetapi-check-active"></span>
    <a href="#" class="facetapi-inactive" id="facetapi-link-12">North West & Other Areas</a>
  </li>
  <li>
    <span class="facetapi-check-active"></span>
    <a href="#" class="facetapi-inactive" id="facetapi-link-13">Yorkshire and the Humber</a>
  </li>
</ul>

最佳答案

您可以使用 CSS 表格

ul { 
  padding: 0px;
  margin: 0px;
  width: 140px;
  background-color: #fffaaa;
  margin-bottom: 10px;
  list-style: none;
}

li {
  display: table;
}

span.facetapi-check-active {
  background-image: url('https://www.drupal.org/files/project-images/Very-Basic-Checked-checkbox-icon.png');
  width: 15px;
  height: 15px;
  background-repeat: no-repeat;
  background-size: 15px 15px;
  display: table-cell;
}

a {
  display: table-cell;
}
<ul>
  <li>
    <span class="facetapi-check-active"></span>
    <a href="#" class="facetapi-inactive" id="facetapi-link-12">North West & Other Areas</a>
  </li>
  <li>
    <span class="facetapi-check-active"></span>
    <a href="#" class="facetapi-inactive" id="facetapi-link-13">Yorkshire and the Humber</a>
  </li>
</ul>

关于css - 如何获取内联 block 元素内的文本以进行识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35988399/

相关文章:

css - 无法将图像正确放入 div

html - CSS Animations 在 CodePen 中工作,但在将它们放入 ASP.Net 元素后它们不工作

javascript - 有没有办法用三元运算符在 html 元素中切换 css 类?

html - 如何使用 ID 处理 Sketch 导出的 SVG

javascript - Chrome 无法正确显示 iframe 和/或转换

html - Div 元素淡出,DIV 中的 <p> 元素淡入

html - 如何将链接置于按钮/链接的中间?

html - 使用 css 添加背景图片,不起作用?

android - 无论屏幕大小如何,如何将元素与背景对齐?

html - 当前页面上的按钮图像