2012-07-17 268 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,你应该很好走。基本上,它会在父项的末尾添加一个伪元素,清除该元素,这会给出一个上下文,以便您的孩子可以很好地玩。