具有固定高度和水平滚动的动态宽度容器 div?
我正在尝试获取一个容器 div,它将水平滚动到视口之外。有点像全屏幻灯片,开头为 #a
,结尾为 #c
。 #a
和 #c
都是固定宽度的 div,而 #b
具有动态宽度的图像内容。我遇到的问题是让 #container
动态更改其宽度以适应 #b
。将 #container 宽度设置为 auto 或 100% 仅使用视口宽度。
我想要的:
[- viewport width -]
--#container---------------------------------------
| -------------------------------------------- |
| | #a | #b... | #c | |
| -------------------------------------------- |
---------------------------------------------------
我的标记:
#container {
height:400px;
}
#a {
float:left;
width:200px;
height:400px;
}
#b {
float:left;
width:auto;
height:400px;
}
#c {
float:left;
width:200px;
height:400px;
}
<div id="container">
<div id="a">fixed width content</div>
<div id="b">dynamic width content</div>
<div id="c">fixed width content</div>
</div>
编辑:我可以使用表格来完成此操作,但希望尽可能避免这种情况。
编辑 2:这是使用表格的工作版本:
#container {
height:400px;
background:#fff;
}
#a {
width:200px;
height:400px;
background:#ccc;
}
#b {
height:400px;
background:yellow;
white-space: nowrap;
}
#c {
width:200px;
height:400px;
background:#ccc;
}
<table cellpadding="0" cellspacing="0">
<tr>
<td id="a">
a
</td>
<td id="b">
<img src="..." />
<img src="..." />
<img src="..." />
</td>
<td id="c">
b
</td>
</tr>
</table>
I'm trying to get a container div that will scroll horizontally beyond the viewport. Sort of like a fullscreen filmstrip with #a
at the beginning and #c
at the end. Both #a
and #c
are fixed width divs, and #b
has dynamic width image content. The problem I'm having is getting #container
to change its width dynamically to accommodate #b
. Setting #container
width to auto or 100% just uses the viewport width.
What I'm after:
[- viewport width -]
--#container---------------------------------------
| -------------------------------------------- |
| | #a | #b... | #c | |
| -------------------------------------------- |
---------------------------------------------------
My markup:
#container {
height:400px;
}
#a {
float:left;
width:200px;
height:400px;
}
#b {
float:left;
width:auto;
height:400px;
}
#c {
float:left;
width:200px;
height:400px;
}
<div id="container">
<div id="a">fixed width content</div>
<div id="b">dynamic width content</div>
<div id="c">fixed width content</div>
</div>
Edit: I can do this with a table, but would like to avoid that if possible.
Edit 2: Here's a working version using tables:
#container {
height:400px;
background:#fff;
}
#a {
width:200px;
height:400px;
background:#ccc;
}
#b {
height:400px;
background:yellow;
white-space: nowrap;
}
#c {
width:200px;
height:400px;
background:#ccc;
}
<table cellpadding="0" cellspacing="0">
<tr>
<td id="a">
a
</td>
<td id="b">
<img src="..." />
<img src="..." />
<img src="..." />
</td>
<td id="c">
b
</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是很好的 css:
漂亮而闪亮的示例: http://jsfiddle.net/KefJ2/
如果您需要更多比添加一张图像更重要的是:
包含更多图像的示例: http://jsfiddle.net/KefJ2/1/
显然,您必须在
#b
中尝试文本和图像布局,但这应该很容易:)Here is good css:
Nice and shiny example: http://jsfiddle.net/KefJ2/
If you need more than one image than add this:
Example with more images: http://jsfiddle.net/KefJ2/1/
Obviously you will have to play around with text and images layout in
#b
but that should be easy enough :)