2012-07-17 161 views
-1

可能重複:
how to create a table layout with float in cssCSS浮子與寬度百分比

#inner 
{ 

height:700px; 

    } 
div.content 
{ 
    float:left; 
    width:95%; 

} 
    div.content span.first 
    { 
     display:block; 
     float:left; 
     width:25%; 
     overflow:hidden; 

    } 
    div.content span.second 
    { 
     clear:both; 
     display:block; 
     float:right; 
     width:25%; 

    } 
    div.content span.third 
    { 
     clear:both; 
     display:block; 
     float:right; 
     width:25%; 

    } 
</style> 

<body> 

    <div id="outer"> 
      <div id="inner"> 
      <div class="content"> 
      <span class="first"> 
      HELLO 
     </span> 
     </div> 

    <div class="content"> 
     <span class="second"> 
     pRERNA 
      </span> 
     </div> 

    <div class="content"> 
     <span class="third"> 
     gOLANI 
     </span> 
    </div>  

工作時像素正在工作,但不是百分比爲什麼?我想創建三個相等寬度的列。如果外部元素爲72%。我想創建72/3的寬度,即24%的寬度。

+0

請解釋一下你在問什麼,讓更多的人可以幫助你! – imakeitpretty 2012-07-17 18:03:44

回答

3

您需要爲父級設置寬度。無論是100%還是像素寬度,否則引擎都不知道從中推導出什麼。

也應該解釋一下你的代碼在做什麼,你想要它做的更好,讓更多的人能幫助什麼,你不趴下票:)

編輯

還在考慮你在這裏展示你可能最終會與INNER父母以外的孩子結束。我會添加一個clearfix到你的樣式表中,只需google clearfix,你應該很好走。基本上,它會在父項的末尾添加一個僞元素,清除該元素,這會給出一個上下文,以便您的孩子可以很好地玩。