CSS - 自动宽度浮动元素(可扩展浮动)

发布于 2024-09-14 12:17:46 字数 155 浏览 2 评论 0原文

我有两个并排的浮动列。用户可以隐藏/折叠该列之一。在这种情况下,我希望另一列扩展以适合整个容器。

这可以用 CSS 实现吗?

在简历中,是否可以使浮子扩展到其容器的大小? 即使元素是浮动的,如果它有 width:auto 它也应该扩展。至少我认为它应该是这样的。

I have two floated collumns side by side. The user can hide/collapse one of that collumns. In that case I want the other collumn to expand to fit the entire container.

Is this possible with CSS?

In resume, it's possible to make a float to expand to the size of it's container?
Even if the element is floated, if it has width:auto it should expand. At least that´s way I think it should work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虚拟世界 2024-09-21 12:17:46

我认为接受的答案实际上不起作用。我只是在尝试同样的事情,这就是解决方案...

aside { 
    float: left;   /* or could also be float: right */
}
main {
    overflow: hidden;
    /* don't float this one */
}

只需确保将可折叠元素 first 放在 HTML 中即可。那么后面的元素就会用完剩余的空间。

尝试一下这里的代码: http://jsfiddle.net/simoneast/qPHgR/2/

I don't think the accepted answer actually works. I was just attempting the same thing, and this is the solution...

aside { 
    float: left;   /* or could also be float: right */
}
main {
    overflow: hidden;
    /* don't float this one */
}

Just be sure to place the collapsible element first in the HTML. Then the following element will use up the remaining space.

Play around with the code here: http://jsfiddle.net/simoneast/qPHgR/2/

情话已封尘 2024-09-21 12:17:46

设置溢出:自动; height:auto; 对于 floatet 元素
:)

set overflow:auto; height:auto; for floatet element
:)

瑕疵 2024-09-21 12:17:46

如果您的左列具有隐式大小,例如 250px,而您的右列仅浮动且没有设置大小,那么当左列折叠时,它应该填充容器。代码如下:

#leftcol{
width:250px;
float:left;
clear:none;
}

#rightcol{
float:left;
overflow:hidden;
width:auto; /* This may or may not work */
}

If your left column has an implicit size, say 250px and your right column is ONLY floated with no set size, then it should fill the container when the left column is collapsed. Code would be as follows:

#leftcol{
width:250px;
float:left;
clear:none;
}

#rightcol{
float:left;
overflow:hidden;
width:auto; /* This may or may not work */
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文