gpt4 book ai didi

html - 了解溢出属性

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:46 25 4
gpt4 key购买 nike

我正在尝试创建一个包含 float 图像列表的 div。由于它们的数量,它们会破坏容器。我希望容器在滚动时水平滚动。目前,它只是断裂,将它们垂直堆叠:

http://jsfiddle.net/tmyie/YUhF9/1/

CSS

.slideshow-container-row-3 {
height: 250px;
background-color: grey;
width: 1025px;
overflow: scroll;
}

.img {
width: 160px;
background-color: orange;
height: 250px;
margin-left: 10px;
float: left;
}

.img:first-of-type {
margin-left: 0;
}

HTML

<div class="slideshow-container-row-3">
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>
<div class="img">.</div>


</div>

最佳答案

您正在使用 float,而不是让它们 display: inline-block; 并在 wrapper 元素上使用 white-space: nowrap;以防止缠绕。

Demo

.slideshow-container-row-3 {
height: 250px;
background-color: grey;
width: 1025px;
overflow: scroll;
white-space: nowrap;
}

.img {
width: 160px;
background-color: orange;
height: 250px;
margin-left: 10px;
display: inline-block;

/* Use these as well */
vertical-align: top;
white-space: normal;
}

Important Note: Make sure you use white-space: normal; for the child elements i.e .img else they will inherit the parent property. Also use vertical-align: top; to the .img as inline-block are aligned to the baseline by default.

关于html - 了解溢出属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21144025/

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