css在一个div中定位2个div

css在一个div中定位2个div,css,html,positioning,Css,Html,Positioning,我有一个100%宽度的主div,其中有两个div。一个是200px的宽度,另一个是100%-200px,我的意思是 -----------------this is main div ------------- | | | ----subdiv1---- -------------subdiv2----------| || | |

我有一个100%宽度的主div,其中有两个div。一个是200px的宽度,另一个是100%-200px,我的意思是

  -----------------this is main div -------------
 |                                               |
 | ----subdiv1---- -------------subdiv2----------|
 ||              | |                            ||
 | --------------   ---------------------------- |
 |-----------------------------------------------|

subdiv1有200像素,subdiv2的宽度将是剩余的空白空间。我在谷歌上搜索,但找不到。

这里有一个可能的解决方案,我使用了一个float:最左边的div使用左边距规则,右边div使用左边距规则:

HTML示例:

<div id="container">
    <div id="left">
        Some content here
    </div>
    <div id="right">
        Some more content goes over here on the right. Let's make this
        content really long to see what happens when we wrap more than
        one or two line's worth. Extra text to fill the void.
    </div>
</div>

这里有一个可能的解决方案,我使用了一个float:最左边div的left规则,右边div的left规则:

HTML示例:

<div id="container">
    <div id="left">
        Some content here
    </div>
    <div id="right">
        Some more content goes over here on the right. Let's make this
        content really long to see what happens when we wrap more than
        one or two line's worth. Extra text to fill the void.
    </div>
</div>

您需要添加float:left;去你的房间。下面是几行代码,它们将生成您所展示的内容

<div>
  <div style="float:left;width:200px;background:#0F0">
  SUBDIV1
  </div>
  <div style="background:#F00;">
  SUBDIV2
  </div>
</div>

简而言之,使用float:left;在细分曲面1上,您需要添加float:left;去你的房间。下面是几行代码,它们将生成您所展示的内容

<div>
  <div style="float:left;width:200px;background:#0F0">
  SUBDIV1
  </div>
  <div style="background:#F00;">
  SUBDIV2
  </div>
</div>
简而言之,使用float:left;在细分曲面1上,可以在左div上浮动:left,在右div上浮动:200px

HTML:

还有一种方法可以使用,那就是替换左边的边距。这很有用,因为您不必在其中放置两次尺寸标注,而且它更容易适应更改

例如,对于10px边框:

如果您尝试使用我提到的第一种技术做同样的事情,您会发现您必须手动计算内容:并修复:

最后,overflow:hidden on容器用于包含浮动。您可能希望改为使用。

您可以在左div中使用float:left,在右div中使用margin left:200px

HTML:

还有一种方法可以使用,那就是替换左边的边距。这很有用,因为您不必在其中放置两次尺寸标注,而且它更容易适应更改

例如,对于10px边框:

如果您尝试使用我提到的第一种技术做同样的事情,您会发现您必须手动计算内容:并修复:


最后,overflow:hidden on容器用于包含浮动。您可能希望改用。

很高兴能为您提供帮助。确保将答案标记为已接受,这样将来的互联网访问者就会知道它对你有帮助。这也会帮助你提高你的接受率。很高兴能帮上忙。确保将答案标记为已接受,这样将来的互联网访问者就会知道它对你有帮助。它还将帮助你提高你的接受率。
#container {
    overflow: hidden;
}
#left {
    float: left;
    width: 200px;
}
#right {
    margin-left: 200px;
}
#container {
    overflow: hidden;
}
#left {
    float: left;
    width: 200px;
}
#right {
    overflow: hidden;
}