无论我如何设置元素样式,我都无法应用任何Flexbox样式。我到处都在寻找解决方案,但找不到任何解决方案(如果这是重复的,很抱歉,因为我找不到问题的答案)。
HTML:
<div class="test">
<div class="test2">
</div>
</div>
CSS:
* {
padding: 0;
margin: 0;
}
.test {
height: 10em;
width: 10em;
background: #333;
}
.test2 {
height: 2.5em;
width: 2.5em;
background: #ff0000;
display: flex;
flex-direction: column;
align-content: center;
justify-content: center;
text-align: center;
}
在此先感谢您提供的任何帮助。
您需要将这些CSS规则添加到父元素中。
在display: flex
元素上设置时,其直接子元素成为flexbox项。在您的示例中,.test2
元素没有任何子元素,因此我假设您可能想添加display: flex
父元素。
.test {
height: 10em;
width: 10em;
background: #333;
display: flex;
align-items: center;
justify-content: center;
}
.test2 {
height: 2.5em;
width: 2.5em;
background: #ff0000;
}
<div class="test">
<div class="test2"></div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句