多个内联div超过容器宽度(Multiple inline divs that exceed the container width)

编程入门 行业动态 更新时间:2024-10-04 09:23:06
多个内联div超过容器宽度(Multiple inline divs that exceed the container width)

我不知道如何保持多个div内联,如果他们的宽度超过容器宽度。如果所有div的宽度大约是1000像素,容器的宽度是500,我希望div与容器重叠,并且水平滚动酒吧出现。

#container {
  overflow: hidden;
  background: red;
  width: 500px;
  height: 500px;
}
#container>div {
  border: 1px solid #000;
  width: 30%;
  height: 100px;
  margin: 10px;
  float: left;
} 
  
<div id="container">
  <div class="first"></div>
  <div class="second"></div>
  <div class="third"></div>
  <div class="fourth"></div>
  <br style="clear: both;">
</div> 
  
 

小提琴: 点击

I can't figure out how to keep multiple divs inline if their width exceeds container width.If the width of all divs is about 1000 px and the container's width is 500 , i want the divs to be overlapped by container , and a horizontal scroll bar to show up.

#container {
  overflow: hidden;
  background: red;
  width: 500px;
  height: 500px;
}
#container>div {
  border: 1px solid #000;
  width: 30%;
  height: 100px;
  margin: 10px;
  float: left;
} 
  
<div id="container">
  <div class="first"></div>
  <div class="second"></div>
  <div class="third"></div>
  <div class="fourth"></div>
  <br style="clear: both;">
</div> 
  
 

Fiddle: Click

最满意答案

不要使用float,使用容器设置为nowrap空白的内联块,然后添加overflow: auto; 到容器根据需要触发滚动条。

的jsfiddle

#container{ white-space: nowrap; overflow: auto; } #container>div{ display: inline-block; }

Don't use float, use inline block with container set to nowrap for white space, and then add overflow: auto; to the container to trigger the scrollbar as needed.

jsFiddle

#container{ white-space: nowrap; overflow: auto; } #container>div{ display: inline-block; }

更多推荐

本文发布于:2023-07-09 10:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   内联   宽度   容器   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!