html - 在 ul -> li -> 设计中 li 不会扩展高度以匹配标签高度

标签 html css

谁能给我解释一下,为什么 li 和 ul 没有在下面的 plunkr 中展开?

我知道有很多关于它的文章,但我发现的只是玩弄 overflow、height、position 和 display css 属性。我不使用任何这些。

a {
        padding: 1em;
        background-color: red;
      }
      ul {
        list-style: none;
        background-color: yellow;
        display: flex; 
      }
      
      li {
        background-color: green;
        display: inline-block;
      }
<!DOCTYPE html>
<html>

  <head>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>

  <body>
   <ul>
     <li>
       <a href="http://google.si">google</a>
     </li>
     <li>
       <a href="http://sometest.com">test item</a>
     </li>
   </ul>
  </body>

</html>

最佳答案

Can someone please explain to me, why li and ul does not expand

因为您的链接仍然是内联的,因此它们的填充会流出行框。

为链接添加display: block

关于html - 在 ul -> li -> 设计中 li 不会扩展高度以匹配标签高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133477/

相关文章:

html - 如何在 bootstrap 4 中设置图标在图像上的位置

jquery - 如果填充了文件名范围,如何将类添加到外部 div

html - IE 中 div 中未对齐的垂直分页器

html - 如何在中间垂直对齐图像和文本?

html - 什么正确使用目标伪类替换多个页面导航上的 'active' 状态?

javascript - Uncaught Error : [$injector:modulerr] & Uncaught ReferenceError: app is not defined

css - 重叠 3 个图像并将它们居中放置在流体容器中

html - 如何使用 Bootstrap 垂直对齐到中间?