2010-10-05 84 views
0

我一直在尽一切可能尝试将侧边栏浮动到左侧,并使其适合旁边的内容div,但它似乎对我来说是不可能的。请帮忙。Divs不会浮动

HTML:

<div class="index-page">  

     <img src="images/hosting-header.png" width="458" height="179" alt="Hosting Header"> 
     <h1> Welcome to Elektrik Host! </h1> 
     <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis 
     egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. 
     Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris 
     placerat eleifend leo.</p> 
     <h1> A little about us </h1> 
     <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis 
     egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. 
     Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris 
     placerat eleifend leo.</p> 
    </div><!-- //index-page --> 
    <div class="sidebar"> 

     <img src="images/sidebar-stickers.png" width="150" height="634" alt="Sidebar Stickers"> 

    </div><!-- //.sidebar --> 

CSS:

.index-page { color: #000; width: 462px; } 
.sidebar { float: right; width: 200px; } 

clearfix:

.clearfix:after { 
    content: "."; 
    visibility: hidden; 
    display: block; 
    height: 0; 
    clear: both; 
} 
+0

然后你错误地将它浮动,你的标记中有'.sidebar {float:right;}'。 – 2010-10-05 03:27:20

回答

0
  1. .sidebar { float: left; width: 200px; }right
  2. 为了让他们身旁:
        - 索引页还需要floatleft太index-page{ float: left;}(FF需求,即不)
        - 移动工具条索引页的前
+0

如果你单独离开'index-page',移动'sidebar'先来,给它一个'width'并定义'float','index-page'会自己处理。 – 2010-10-05 03:37:57

+0

在我的测试中,如果index-page没有浮动,那么它显示在下面(在我的情况下是FF)。哦,IE不需要。但FF要求@ _ @ – pinichi 2010-10-05 03:40:52

0

您可以按照本教程:http://css.maxdesign.com.au/floatutorial/index.htm

CSS代码

.floatright { float: right; } 

HTML代码

<p> 
<img class="floatright" src"images/sidebar-stickers.png" width="150" height="634" alt="Sidebar Stickers"> 
<p> 

你不需要做的正好类应用单一的形象。

PK

2

我总觉得它更容易把float -ing内容提前,使得这样它的内容,所以我切换侧边栏来提前index-page股利,并用以下CSS:

.sidebar { 
    width: 200px; 
    float: left; 
    } 

演示结束于JS Bin