让 Div 填充未指定的宽度 [图片]
如果您有 Vaadin 或 GWT 或类似经验,这个问题可能更容易理解,但良好的 CSS 和 Web 开发技能应该就足够了。
我陷入了两难的境地。在我们的 Web 应用程序的视图中,我们有三个面板,两个并排在顶部,一个在底部,它们所占的宽度应与上面两个面板的宽度总和形成一个由三个面板组成的“正方形”一样多。
这里有一张图片来解释它:
问题只是一个面板(顶部left)可以有一个静态的指定宽度,因为那里显示的数据是非常可预测的。右上角的另一个将保存不同的内容,宽度可能会变化 +-100 像素。
现在我希望底部面板的宽度调整并填充与上面面板相同的宽度。
接下来是 Vaadin 部分(这是开发 Web 应用程序的框架)。我尝试过将上部面板放在 HorizontalLayout
中,它与底部面板一起位于 VerticalLayout
内。我希望我可以将底部面板设置为 setWidth("100%")
,并且它将其宽度调整为 VerticalLayout
的宽度,但是当然这不起作用,因为 VerticalLayout
没有指定的宽度。
然后我使用 2 x 2 的 GridLayout 执行测试,其中顶行有两个单元格,每个单元格中都有布局,底行有两个单元格中的底部布局。 代码:
GridLayout grid = new GridLayout(2, 2);
SHorizontalLayout h1 = new SHorizontalLayout();
SHorizontalLayout h2 = new SHorizontalLayout();
SHorizontalLayout h3 = new SHorizontalLayout();
h1.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h2.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h3.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h1.setSizeFull();
h2.setSizeFull();
h3.setSizeFull();
h1.setStyleName("test-layout1");
h2.setStyleName("test-layout2");
h3.setStyleName("test-layout3");
grid.addComponent(h1, 0, 0);
grid.addComponent(h2, 1, 0);
grid.addComponent(h3, 0, 1, 1, 1);
outerHLayout.addComponent(grid);
这将给出以下结果:
但是底部单元格的宽度当它聚焦在 FireBug 工具中时,上面的两个组合:
但 Vaadin 会自动生成一个 div (
) 将内容的宽度限制为内容大小(即使内容设置为 setSizeFull())。所以我真的很想得到一些帮助来解决这个问题,一般使用 CSS 或来自使用 Vaadin 的人来帮助我如何指定网格,这样它就不会生成限制内容宽度的内部单元格 div。
如果您需要我提供更多信息,请询问我!
我知道这是一个冗长乏味的问题,所以我真的很感谢读到这里的你们,谢谢!
This question might be more comprehensible if you have experience of Vaadin or GWT or similar, but good CSS and web development skills should be sufficient.
I'm in a dilemma. In a view in our web application we have three panels, two at the top side by side and one at the bottom that should take up as much width as the two above combined making a "square" of three panels.
Here's an image to explain it:
Problem is only one panel (the top left) can have a static specified width because the data displayed there is very predictable. The other one on the top right will hold differing content that could vary +-100 pixels in width.
Now I want the bottom panel to have its width adjusted and fill the same width as the panels above.
And here comes the Vaadin part (which is the framework the web application is developed in). I've tried just having the upper panels in a HorizontalLayout
which is inside a VerticalLayout
together with the bottom panel. I would have hoped that I could set the bottom panel to setWidth("100%")
and it would adjust its width to how wide the VerticalLayout
was, but of course this doesn't work since the VerticalLayout
doesn't have a specified width.
Then I performed a test using a GridLayout
which was 2 x 2 where the top row had two cells with layouts in each and the bottom row had the bottom layout in the two cells. Code:
GridLayout grid = new GridLayout(2, 2);
SHorizontalLayout h1 = new SHorizontalLayout();
SHorizontalLayout h2 = new SHorizontalLayout();
SHorizontalLayout h3 = new SHorizontalLayout();
h1.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h2.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h3.addComponent(new Embedded(null, new ThemeResource("../m2m/img/lock_20x20.png")));
h1.setSizeFull();
h2.setSizeFull();
h3.setSizeFull();
h1.setStyleName("test-layout1");
h2.setStyleName("test-layout2");
h3.setStyleName("test-layout3");
grid.addComponent(h1, 0, 0);
grid.addComponent(h2, 1, 0);
grid.addComponent(h3, 0, 1, 1, 1);
outerHLayout.addComponent(grid);
This will give this result:
However the bottom cell has the width of the two upper combined when it's focused in the FireBug tool:
But Vaadin automatically generates a div (<div style="float: left; margin-left: 0px;">
) that restricts the width of the content to the content size (even though content is set to setSizeFull()).
So I would really like to get some help with this problem in general using CSS or from someone used to Vaadin to help me with how to specify the grid so that it doesn't generate this inner cell div that restricts the width of the content.
If you need me to provide any more information then please ask me!
I know this is a tediously long question so I would really like to thank you who have read this far, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 Vaadin/GWT,但就 CSS 和 HTML 而言:
默认情况下
占据所有空间,因此通过设置第一个内部
float:left; 我们改变它的渲染流程,因此下一个 div 将尝试占据所有剩余空间(或尽可能拉伸)。
overflow: auto
或overflow: hide
触发这些 div 的重绘/重新计算,以便动态宽度是正确的。display: inline-block;
消除了以block
模式渲染时 div 宽度的错误计算,且边距接近(“与以下行相同”)浮动
块。示例:http://jsfiddle.net/MUN8E/3/。使用 Chrome、IE9 进行测试。 (似乎不适用于 IE7,请告诉我是否需要 IE7 支持)
修改的结构
其结构与 @Marthin 的答案相同。
如果容器
div
不是浮动
,它将占据所有空间。我不确定你是否可以在 Vaadin 中这样做,但根据 @Marthin 答案,你可以做这样的事情(使用相同的结构):
和 CSS 样式:
希望它有帮助。
I am not familiar with Vaadin/GWT, but in terms of CSS and HTML:
By default
<div>
takes up all the space, so by setting first innerfloat:left;
we change the rendering flow for it, thus next div will try to take all the space left (or stretch as much as possible).overflow: auto
oroverflow: hidden
triggers redrawing/recalculation of those divs, so that dynamic width is correct. Thedisplay: inline-block;
removes miscalculations from div's width from when it is rendered in ablock
mode with margins near ("on the same line as")floated
block.Example: http://jsfiddle.net/MUN8E/3/. Tested with Chrome, IE9. (Seems not to work with IE7, tell me if IE7 support is required)
Modified stucture
Which has the same structure as in @Marthin's answer.
If container
div
is notfloated
it will take all the space.I am not sure whether you can do it that way in Vaadin, but based on @Marthin answer, you could do something like this (using same structure):
And CSS styles:
Hope it helps.
我的建议是,您将 3 个视图添加到一个 VerticalLayout 的主容器中,并将两个较小的顶部布局包装在一个horozontallayout 中,而horozontallayout 又会添加到主容器中。
像这样的东西
My suggestion is that you let your 3 views get added in a main container that is a VerticalLayout and that your two smaller top layouts get wrapped within a horozontallayout that in turn also gets added to the main container.
Somehitng like this