html - 侧边栏定位不正确

标签 html css

基本上,我不明白为什么 不在右上角?它把自己定位在底部,尽管根据我的理解它应该在右上角?

详细代码见JSfiddle

http://jsfiddle.net/5JhMj/

#content section {
padding: 4%;
width: 70%;
float: left;
background-color: white;
margin-bottom:8%;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;

aside {
width: 30%;
float: right;
background-color: green;

最佳答案

您正在围绕最后一个部分元素 float 侧边栏。

取而代之的是,将您的部分包裹在您漂浮的另一个容器周围。然后让你的侧边栏漂浮在那个新容器旁边。

<div class="container">
    <div class="section-container">
        <section>...</section>
    </div>
    <aside>
        ...
    </aside>
</div>

CSS

.section-container{
    width: 70%;
    float: left;
}

aside {
    width: 29%;
    float: right;
    background-color: green;
}   

fiddle : http://jsfiddle.net/5JhMj/2/

关于html - 侧边栏定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21135364/

相关文章:

javascript - 我如何应用另一个事件监听器?

jQuery 滚动事件与 CSS 悬停相矛盾

html - Twitter bootstrap v3x 未正确显示复选框

html - flex 包装 : nowrap width doesn't include children

html - 内容重叠 Wordpress 中的固定标题菜单

php - 是否可以使用 HTML 表单/PHP 脚本上传文件夹

html - 如何只在thead中绘制外边框

css - 内联 contenteditable 标签无法在 IE 中正确对齐

jquery - 页面加载时的 Fancybox 叠加颜色

javascript - Meteor 应用程序构建奇怪的文件;没有js/css资源