html - 无序列表的问题

标签 html css html-lists listitem

所以我有一个“热门新闻文章”列表,它只占页面一侧的一小部分。 但是如果标题比 div 的宽度长,它不会中断句子。它只是将整个内容放在下一行。 我一直没能找到解决办法。

http://codepen.io/anon/pen/WrjPQo

<li>
    <p class="number">1</p>
    <a href="#"><h3>Virtual Reality Being Used in School</h3></a>
</li>

谢谢

最佳答案

您可以通过在 H3 中添加数字来解决此问题。

或者你甚至可以使用列表的编号,或者 H3 的 ::before 伪元素来生成编号,所以你甚至不需要它的标记。

下面的例子展示了后者。样式不完美,只是展示了如何在没有标记的情况下添加数字。

ul.headings {
 list-style-type: none; 
}
.headings {
  counter-reset: header-counter;
}
.headings li::before {
  /* Showing and incrementing the counter */
  content: counter(header-counter);
  counter-increment: header-counter;

  /* Some styling to make it red and round and white, etc. */
  display: inline-block;
  text-align: center;
  width: 20px;
  height: 20px;
  border-radius: 20px;
  background-color: red;
  color: white;
}
<ul class="headings">
  <li>Lorem ipsum</li>
  <li>Lorem ipsum</li>
  <li>Lorem ipsum</li>
  <li>Lorem ipsum</li>
  <li>Lorem ipsum</li>
</ul>

关于html - 无序列表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34711638/

相关文章:

javascript - Iframe 图片默认缩小问题

css - 无限的 Div 宽度?是否可以?

css - 下面带有 Logo 的菜单不起作用

javascript - 扩展-可折叠 HTML 列表- ul - li - Javascript

html - 无法在 React 中上传文件时附加到 formData 对象

html - IE9 HTML 元素调整大小错误与最小宽度子 Div

javascript - 我的标签不算数

jQuery 对话框为页面增加了额外的高度

html - 在顶部为 <li> 中的事件链接添加一个 bg-image,可能吗?

html - 重叠选项卡式容器列表项