简体   繁体   English

初学者CSS定位(浮动)

[英]Beginner CSS positioning (floating)

I'm new to CSS positioning and I'm trying to fix a problem I'm having regarding the positioning of my div's in my layout. 我是CSS定位的新手,我正在尝试解决我在我的布局中定位div的问题。

I'm trying to create this right here: ( http://www.subcide.com/images/dynamic/css-layout/floatexample3.gif ) 我正试图在这里创建:( http://www.subcide.com/images/dynamic/css-layout/floatexample3.gif

however, when I follow the instructions precisely, something happens. 然而,当我准确地遵循指示时,会发生一些事情。

Here is the code and the working example to my problem ( http://rendera.heroku.com/usercode/a8dd085e8500914d5c8c3a89880cb3d513b54cdb ) 以下是我的问题的代码和工作示例( http://rendera.heroku.com/usercode/a8dd085e8500914d5c8c3a89880cb3d513b54cdb

Notice how the dark green div isn't lining up with the normal green div. 请注意深绿色div如何与正常的绿色div对齐。 It's instead leaving that white space to the right, which I don't need. 而是将该空白区域留在右侧,这是我不需要的。 How can I fix this? 我怎样才能解决这个问题? I used the float tag in my CSS to float the dark green to the right, and to no avail. 我在我的CSS中使用float标签将深绿色向右浮动,但无济于事。

I apologize for such a juvenile question. 我为这样一个少年问题道歉。 I figure this is the best place to post and I don't know where else to look for help. 我认为这是发布的最佳地点,我不知道在哪里寻求帮助。 I hope I can ask more questions in the future. 我希望将来可以提出更多问题。

Change: 更改:

#Content{
    background:green;
    margin-right:280px;
}

to: 至:

#Content{
    float: left;
    background:green;
    width:480px;
}

From the tutorial you're working on the layout should be: 从您正在处理布局的教程应该是:

<div id="page-container">
    <div id="main-nav">Main Nav</div>       
    <div id="header">Header</div>
    <div id="sidebar-a">Sidebar A</div>
    <div id="content">Content</div>
    <div id="footer">Footer</div>
</div>

In your code, you have: Header, content, sidebar, footer. 在您的代码中,您有:标题,内容,侧边栏,页脚。

Switch the order that content and sidebar appear in your code and it will work. 切换内容和侧边栏在您的代码中出现的顺序,它将起作用。

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

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