html - 在一行中查看主要内容和侧边栏。 float :right not working as expected

标签 html css css-float

我想在一行中并排查看主要内容和侧边栏。 很简单,我想,只需添加一个 float:right;但事实证明这并不容易。

您可以在此处找到准备好的 jsfiddle:http://jsfiddle.net/W3MKx/

侧边栏(带有输入框的部分)的宽度应始终为 200 像素。

最佳答案

我建议执行以下操作:( working jsFiddle )

在不更改 HTML 结构的情况下应用以下 CSS:

#all {
    background: blue;
    overflow:hidden; /* This is mandatory to make the parent wrap around the children   */
}

#ball {
    background: red;
    float: right; /* float sidebar to the right */
    width:200px; /* constant width as you requested */
}

#chat{
    width:calc(100% - 210px); /* You can set the width in any way you choose - just make sure to leave room for the sidebar */
    float:left; /* float the chat to the left */
}

当使用 float 元素时,最好将 overflow:hidden; 设置为容器 - 这将强制它包裹所有的 child ,无论他们的高度如何。您还必须设置聊天的宽度,以便为侧边栏留出空间。将聊天 float 到左侧,将侧边栏 float 到右侧。

关于html - 在一行中查看主要内容和侧边栏。 float :right not working as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17615970/

相关文章:

javascript - 我应该在哪里包含 JS 文件

javascript - 所有页面的一个源表单

css - 我如何让 Twitter Widget 像任何其他元素一样运行?

javascript - 用于禁用表单输入的 CSS

html - div 与 fixed 左对齐,另一个 div 与 100% 对齐

html - 将 float 导航元素保持在一行

javascript - 在 CSS 动画之后滚动到 anchor ?

html - 如何将登录 float 到右侧?

html - 三列,内部自动换行,但元素之间没有换行符

CSS使图像填充可用宽度