使用 CSS 设置弹性项目相对于其他弹性项目的增大程度

cssweb developmentfront end technology更新于 2025/7/5 5:32:17

使用 flex-grow 属性增加弹性项目的大小。可将其用于一个或多个弹性项目。

示例

您可以尝试运行以下代码来实现 flex-grow 属性。此处 Q3 弹性项目比其他项目更大 −

<!DOCTYPE html>
<html>
   <head>
      <style>
         .mycontainer {
            display: flex;
            background-color: orange;
            align-content: space-between;
         }
         .mycontainer > div {
            background-color: white;
            text-align: center;
            line-height: 40px;
            font-size: 25px;
            width: 100px;
            margin: 5px;
         }
      </style>
   </head>
   <body>
      <h1>Quiz</h1>
      <div class = "mycontainer">
         <div style = "flex-grow: 1">Q1</div>
         <div style = "flex-grow: 1">Q2</div>
         <div style = "flex-grow: 20">Q3</div>
         <div style = "flex-grow: 1">Q4</div>
         <div style = "flex-grow: 1">Q5</div>
      </div>
   </body>
</html>

相关文章


有用资源