gpt4 book ai didi

html - 如何让元素在 Flex 中堆叠?

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:11 25 4
gpt4 key购买 nike

我正在尝试制作剪刀石头布游戏,但在堆叠元素时遇到了问题。我在一行中有三个图像,我想在它们下面显示第四个图像(这个图像将是显示石头、布或剪刀的结果图像)。

我尝试使用 flex-wrap、更改宽度等,经过一个小时的搜索,我想我会问问你们谁可能会在一分钟内解决它 哈哈 这是我的代码,在此先感谢您的帮助:D

@import url("https://fonts.googleapis.com/css?family=Germania+One");
$primary-color: #000000;
$serif: "Germania One",
cursive;
html {
background: #4d1c17;
font-size: 66%;
}

h1 {
font-size: 4rem;
text-align: center;
margin-top: 100px;
}

h2 {
text-align: center;
font-size: 3rem;
}

h1,
h2 {
color: $primary-color;
font-family: $serif;
}

.container {
text-align: center;
width: 100%;
img {
height: 12rem;
padding: 20px;
&:hover {
height: 13rem;
}
}
}

#rock,
#paper,
#scissor {
display: flex;
justify-content: center;
border-radius: 20px;
cursor: pointer;
}

#scissor {
margin-left: 30px;
padding-left: 10px;
color: green;
}

p {
font-size: 4rem;
width: 100%;
height: auto;
margin-top: 200px;
display: flex;
justify-content: center;
}

#rock_win,
#paper_win,
#scissor_win {
justify-content: center;
width: 50%;
height: auto;
flex-wrap: wrap;
border-radius: 20px;
cursor: pointer;
}

#scissor_win {
margin-left: 30px;
padding-left: 10px;
}
<h1>Rock, Paper, Scissor's</h1>
<h2>Choose your fate</h2>
<div class="container">
<div class='items'>
<div id='rock'><img src='https://maxcdn.icons8.com/Share/icon/ios7/Hands//hand_rock1600.png' /> </div>
<div id='paper'><img src="https://maxcdn.icons8.com/Share/icon/Hands//hand1600.png" /> </div>
<div id='scissor'><img src="https://maxcdn.icons8.com/Share/icon/ios7/Hands//hand_scissors1600.png" /> </div>
</div>
<div id='scissor_win'><img src="https://maxcdn.icons8.com/Share/icon/ios7/Hands//hand_scissors1600.png" /> </div>
</div>
<p></p>

最佳答案

display: flex; 设置需要应用于容器/父元素,而不是 flex 元素/子元素。

因为你有 .container 的结构作为 items#scissor_win 的容器,以及 items再次包含三个要堆叠的元素,CSS 规则应该(部分)如下所示:

.container {
display: flex;
flex-direction: column;
}
.items {
display: flex;
flex-direction: column;
}

单个元素不需要 display: flex,除非您想使用 flex 将它们的内容居中。

关于html - 如何让元素在 Flex 中堆叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46526793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com