简体   繁体   English

具有相对宽度的两列布局?

[英]two-column layout with relative width?

I have a two column layout, using a container and a div called "left" and a div called "Right". 我有两列布局,使用一个容器和一个名为“ left”的div和一个名为“ Right”的div。 How do I make sure that the div#right is only 500px, but div#left is as big as the user's browser will allow ...? 如何确定div#right只有500px,但div#left与用户浏览器允许的尺寸一样大?

Here's what I have now: 这是我现在所拥有的:

<div id="container">
  <div id="left" style="float:left"> </div>
  <div id="right" style="float: right; width: 500px"> </div>
</div>

Don't float the left div to the left. 不要将左div浮动到左侧。 If you leave it "unfloated", then it will be the main content and automatically fill the available space. 如果您将其保留为“未浮动”,则它将成为主要内容并自动填充可用空间。

You can do it by unfloating the #left div and giving it a padding-left that equals the #right div's width (this makes room for the right div). 您可以通过将#left div浮动并给其padding-left使其等于#right div的宽度来做到这一点(这为右div腾出了空间)。 Finally, you'd need to swap the source order of both div's. 最后,您需要交换两个div的源顺序。

<div id="container">
    <div id="right" style="float: right; width: 100px; "> </div>
    <div id="left" style="padding-right: 100px; "> </div>
</div>

You can see it in action here . 您可以在此处查看它的运行情况

Change style of you left div to: 将左div样式更改为:

<div id="left" style="margin-right:500px"></div>

This will make sure that content won't flow under the right floating div when content in the left one takes more vertical space than content in the right one. 这样可以确保当左侧的内容比右侧的内容占用更多的垂直空间时,内容不会在右侧的div浮动。

Important 重要

Don't forget to put the floated div in front of the unfloated one. 别忘了将浮动div放在未浮动的div前面。 So put your right one first in the markup and then the left one. 因此,将您右边的一个放在标记中,然后再左边的一个。

Solution to your particular problem 解决您的特定问题

So you have two div elements 所以你有两个div元素

<div id="endants-content">
    <div id="screenshot-preview">...</div>
    <div id="endants-main-content">...</div>
</div>

And CSS should be like this to make it work as expected: CSS应该像这样使它按预期工作:

div#endants-content
{
    /* put min-width here is you need it */
}

div#screenshot-preview
{
    float:right;
    width:30%;
}

div#endants-main-content
{
    margin-right:30%;
    overflow:auto;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM