我如何在Div中获取物品以垂直堆叠
我试图制作一个模拟的在线商店,无法弄清楚如何用其图像堆叠项目描述。我在网格容器中有所有东西。我可以单独集中每个元素,但是当我尝试将图像堆叠在删除/下拉/下拉按钮上时,它们会在框中创建2个新列。有没有办法将图像放在描述的顶部,然后将两个元素放在下拉菜单和按钮的顶部?
#column_left{
display: grid;
width:100%;
height: 900px;
border: solid 2px black;
grid-template-rows: 33% 33% 33%;
}
#column_right {
display: grid;
width:100%;
height: 900px;
border: solid 2px black;
}
.item {
border: solid 2px black;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.sample_img {
height: 50%;
width: auto;
}
<div class="item">
<img class="sample_img" src="https://st2.depositphotos.com/3080513/7014/i/600/depositphotos_70144489-stock-photo-t-shirt-template.jpg">
<p>Sticks T-shirt</p>
<label for="size">Choose a Size</label>
<select name="size" class="size" >
<option value="XS">XS</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
<option value="XXL">XXL</option>
</select>
<button class="addToCart" type="submit">Add to Cart</button>
</div>
Im trying to make a mock online store and cannot figure out how to stack an items description with its image. I have everything inside a grid container. I can center each element individually but when I try to stack the image over the desription/drop down/button they create 2 new columns in the box. Is there a way I can put the image on top of the description and then both of those elements on top of the dropdown menu and button?
#column_left{
display: grid;
width:100%;
height: 900px;
border: solid 2px black;
grid-template-rows: 33% 33% 33%;
}
#column_right {
display: grid;
width:100%;
height: 900px;
border: solid 2px black;
}
.item {
border: solid 2px black;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.sample_img {
height: 50%;
width: auto;
}
<div class="item">
<img class="sample_img" src="https://st2.depositphotos.com/3080513/7014/i/600/depositphotos_70144489-stock-photo-t-shirt-template.jpg">
<p>Sticks T-shirt</p>
<label for="size">Choose a Size</label>
<select name="size" class="size" >
<option value="XS">XS</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
<option value="XXL">XXL</option>
</select>
<button class="addToCart" type="submit">Add to Cart</button>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,将其添加到.Item类
中,图片和其余内容将在另一个下方
Add this to .item class
in this case, the picture and the rest of the content will be one under the other
您应该能够设置弹性方向。
在这种情况下,您可能不需要使用网格。
是您大多可能选择的两个选项。改变弹性方向将改变证明内容和对齐项目的合理性,从本质上扭转它们。您也可以执行行反向和列反向,如果需要,将其向后进行。
You should be able to set a flex-direction.
You probably don't need to use grid in this situation.
are the two options you will mostly likely choose from. Changing the flex direction will change what justify content and align items do though, essentially reversing them. You can also do row-reverse and column-reverse to make it backwards if you want.
需要使用
flex-direction
或flex-flow
column
在这种情况下,在这种情况下,.Item
。Need to use
flex-direction
orflex-flow
column
on the parent, in this case.item
.