在 CSS 中将 flex 项目对齐到容器顶部

cssweb developmentfront end technology更新于 2024/9/21 1:16:17

使用 align-items 属性并将其值设置为 flex-start,即可将 flex 项目对齐到顶部。

您可以尝试运行以下代码来实现 flex-start 值

示例

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            height: 300px;
            background-color: red;
            align-items: flex-start;
         }
         .mycontainer > div {
            background-color: white;
            text-align: center;
            line-height: 60px;
            font-size: 30px;
            width: 100px;
            margin: 5px;
         }
      </style>
   </head>
   <body>
      <h1>Quiz</h1>
      <div class = "mycontainer">
         <div>Q1</div>
         <div>Q2</div>
         <div>Q3</div>
         <div>Q4</div>
         <div>Q5</div>
      </div>
   </body>
</html>

相关文章


有用资源