引导程序-4证明内容不适用于flex列



我使用的是bootstrap-4,我不明白为什么justify-content-around适用于flex-row而不是flex-column?我为div.item2应用了flex-column justify-content-around,但它不起作用。但当我用flex-row justify-content-around代替div.main时,它是有效的!我怎样才能让它工作?我使用css只是为了颜色。这是我的代码:

.main{background-color:pink;}
.item1{background-color:red;}
.a{background-color:green;} 
.b{background-color:yellow;} 
.c{background-color:blue;}
<head>
<!-- CSS Stylesheets  -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css">
<!-- Bootstrap Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div class="main d-flex flex-row justify-content-around bd-highlight">
<div class="item1 d-flex p-2 bd-highlight">Flex item 1</div>
<div class="item2 d-flex flex-column justify-content-around bd-highlight">
<div class="a p-2 bd-highlight">Flex item 2.1</div>
<div class="b p-2 bd-highlight">
<h2 class="price-text">Flex item 2.2</h2>
<p>fermentum iaculis eu</p>
<p>lectus vestibulum mattis</p>
<p>cursus in hac</p>
<button class="btn btn-lg btn-block btn-outline-dark" type="button">Sign Up</button>
</div>
<div class="c p-2 bd-highlight">Flex item 2.3</div>
</div>
</div>
</body>

justify内容属性对齐灵活容器的项当项目没有使用主轴上的所有可用空间时https://www.w3schools.com/cssref/css3_pr_justify-content.asp

在您的案例中为the items use all available space(.item2的高度=内部内容的高度=没有可用空间=没有视觉更改(。

非常简单的代码示例显示了这一点:向.item2添加一些高度(例如600px(:

.main{background-color:pink;}
.item1{background-color:red;}
.a{background-color:green;} 
.b{background-color:yellow;} 
.c{background-color:blue;}
aside{
border: 5px solid green; 
height: 600px;
}
#stroke{
border: 5px solid red;
}
<head>
<!-- CSS Stylesheets  -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css">
<!-- Bootstrap Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div class="main d-flex flex-row justify-content-around">
<main class="item1 d-flex p-2 bd-highlight">Flex item 1</main>
<aside class="item2 d-flex flex-column justify-content-around">
<div class="a p-2 bd-highlight">Flex item 2.1</div>
<div id="stroke" class="b p-2 bd-highlight">
<h2 class="price-text">Flex item 2.2</h2>
<p>Nested item 1</p>
<p>Nested item 2</p>
<p>Nested item 3</p>
<button class="btn btn-lg btn-block btn-outline-dark" type="button">Sign Up</button>
</div>
<div class="c p-2 bd-highlight">Flex item 2.3</div>
</aside>
</>
</body>

最新更新