div 并排浮动并溢出?
我有一个 div 包装器,在它里面,我希望 div 并排放置。我希望包装纸侧面是固定的,这样当添加更多的 div 时,它们会水平溢出!
另外,我希望包装纸宽度是固定的!所以我确实希望里面的帖子溢出到包装纸内!
我想使用一个类,这样我就有了类似
<div id="wrapper">
<div class='post'>Post 1</div>
<div class='post'>Post 2</div>
<div class='post'>Post 3</div>
</div>
我该怎么做?! :p
干杯!!
I have a div wrapper, and inside it, i want divs to be side by side. I want the wrapper side to be fixed, so that as more divs are added, they overflow horizontally!!
Also, I want the wrapper width to be fixed! So I do want the posts inside to overflow inside the wrapper!
I want to use a class, so that I have something like
<div id="wrapper">
<div class='post'>Post 1</div>
<div class='post'>Post 2</div>
<div class='post'>Post 3</div>
</div>
How do I do that?! :p
Cheers!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找这样的东西吗?
这利用了包装器内的第二个
div
:包装器本身具有固定宽度,并且overflow-x
设置为滚动:Are you after something like this?
That makes use of a second
div
inside your wrapper: the wrapper itself has a fixed width, andoverflow-x
set to scroll:此处为 Jfiddle 示例
Jfiddle sample here
将包装器 div 设置为具有溢出:用于滚动的自动宽度,用于调整大小的自动宽度(尽管您需要绝对定位才能正常工作,我相信 - 请记住将父级设置为相对位置以获得准确的顶部:x 和左侧:x在子 div 中)然后 float:left .post 类。
Set the wrapper div to have overflow:auto for scrolling, auto width for resizing (although you'll need to position absolute for that to work correctly I believe- remember to set the parent to position relative for accurate top:x and left:x in sub div's) then float:left the .post class.
据我了解,您希望您的帖子水平滚动并并排放置。
为了实现这一点,您需要添加一个额外的包装器,如下所示:
这是实现所需效果的 css:
工作示例可以在此处找到:
http://jsfiddle.net/QNXmk/1/
As far as I understand you want your posts to be scrolled horizontally and sitting side by side.
To achieve this you will need to add an additional wrapper like so:
Here's the css to achieve the desired effect :
A working example can be found here :
http://jsfiddle.net/QNXmk/1/
我想补充一点,您将不知道内容容器的总宽度。使总宽度基于帖子总宽度总和的唯一解决方案是使用 javascript。
下面是一个执行此操作的小脚本示例:
通过此脚本,您可以将帖子容器设置为正确的大小,而无需在 css 中显式传递它。
I´d like to add that you will not know the total width of your content container. The only solution for having the total width based in the sum of the total of your posts widths is using javascript.
Here is an example of a little script that will do this:
With this, you will set your posts container to the correct size without passing it explicitly in the css.