代码之家  ›  专栏  ›  技术社区  ›  Louis W

布局问题:固定大小的边栏,带流体内容和清除

css
  •  1
  • Louis W  · 技术社区  · 17 年前

    我需要一个固定大小的侧边栏和一个流动内容区域的CSS布局。问题是,这种格式的大多数CSS布局都使用浮动来定位侧边栏。因为这个,我不能用一个清晰的:都在内容区内。

    查看附加的HTML。内容区在浮动时跳到导航内容的底部。

    我需要这种类型的CSS布局的解决方案,它仍然允许我在内容区域内使用float/clear。

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <style type="text/css" media="screen">
            body {
                margin: 0;
                padding: 0;
            }
    
            #nav {
                float: left;
                width: 160px;
            }
    
            #content {
                margin: 0 0 0 200px;
                background-color: green;
            }       
    </style>
    </head>
    <body>
    <div>
    
        <div id="nav">
    
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
            This is the nav content<br/>
    
        </div>
        <div id="content">
    
            This is the main content<br/>
            This is the main content<br/>
            This is the main content<br/>
            This is the main content<br/>
    
    
            <div style="padding: 10px; float: left; width: 100px; background-color: yellow;">Left</div>
            <div style="padding: 10px; float: right; width: 100px; background-color: orange;">Right</div>
    
            <div style="clear: both;"> </div>
    
            (This shouldn't be way down here) This is the main content<br/>
            This is the main content<br/>
            This is the main content<br/>
            This is the main content<br/>
    
        </div>
    </div>
    </body>
    </html>
    
    2 回复  |  直到 17 年前
        1
  •  2
  •   Mottie    17 年前

    我把导航系统从“float:left”;改为“position:absolute;”。你想这样做吗?

        2
  •  0
  •   PetersenDidIt    17 年前

    试试看: http://matthewjamestaylor.com/blog/perfect-2-column-left-menu.htm

    对于跨浏览器工作并允许在两列中使用浮动和清除的不同数字列布局来说,这是一个很好的开端。还修复了具有完整列背景色的问题。通过让“main”列在HTML中排在第一位,而不是排在通常具有不重要信息的中心内容的左栏之后,这也是一种SEO友好的方式。