2013-03-06 65 views
0

(html/css)動態寬度容器上節的寬度是否相等?

如何設置動態寬度的容器,但其中的每個部分具有相同的寬度,以便它們都與容器同時調整大小?

.container{ 
width:80%; 
} 
.section{ 
position:relative; 
float:left; 
width: 80%/6; <---- pseudo code 
} 

有6個相同的部分。例如,如果.container是900px,那麼每個.section將是150px。如果.container是1200px,那麼每個.section將是200px。

+0

您至少應該指定一種語言。 – Gaminic 2013-03-06 16:58:28

+0

它是html/css ... – Windbrand 2013-03-06 18:35:13

回答

0

我最近開始自己的網站開發。 但是,我希望這個答案可以幫助你。

If your class="section" is within your  class="container" , your browser will  
assume that your class="section"  width is part of it's parent. It's parent is in  
this case the  class="container". 


.container{ 
    width:80%; 
    } 


The  class="container"  width is based upon the width of it's parent. 
The correct formula for this is: target/context=result 

Thus your class="container"  width is in this case 80% and this based on the width  
of the parent of your  class="container". 

Your  class="section"  width is inside your  class="container" and is in  
this case 80%, thus this width is based on it's parent width. 
So your  class="container"  is now seen as 100% and your class="section"  is 
80% of your  class="container". 

希望這會有所幫助。