2015-09-16 123 views
0

问题是#lesson容器不适合内#container。我怎样才能让只有3个容器适合一列? CSS忍者,我需要你的帮助:)容器内不适合大

enter image description here 我的CSS:#container - 主容器,#first - 绿色容器,#lesson - 灰色的div。

#container { 
    position: relative; 
    top: 70px; 
    left: 80px; 
    width:100%; 
    height:80%; 
} 

#first { 
    background-color: #A1D490; 
    width:45%; 
    height:100%; 
    float:left; 
    border:2px solid black; 
    margin: 5px; 
} 

.lesson { 
    position: relative; 
    background-color: #DCDDDE; 
    margin:10px; 
    width:200px; 
    height:200px; 
    border:1px solid; 
    text-align: center; 
} 

HTML:

<div id="container"> 
    <div id="first"> 
     <tpl for="."> 
     <div class="lesson"; > 
      <p class="txt"><b>Lesson:</b> {lesson} </p> 
      <p class="txt"><b>Score:</b> {score}</p> 
     </div> 
     </tpl> 
    </div> 
    <div id="second"> 
    </div> 
    </div> 
+0

它为我工作。 [小提琴](http://jsfiddle.net/8ms92uu9/1/) – CodeRomeos

+0

首先,你有没有理由使用'position:relative'和'float:left'? –

+0

也是因为你已经漂浮了##第一个。使用清除:既清除浮游物。 – CodeRomeos

回答

1

有关大一个,你只需要从ID首先删除高度100%装配容器

#first { /* height: 100% */ } 
+0

谢谢!现在它工作了! –

+0

但是仍然有新的框添加到底部,我希望它们添加到下一列。这可能吗? (列中的实例3) –

0

Codepenhttp://codepen.io/noobskie/pen/dYGLeo

这似乎是我在这里工作的罚款。你确定你没有任何其他的CSS被应用和覆盖规则的地方?

HTML

<div id="container"> 
    <div id="first"> 
    <div class="lesson"> 
      <p class="txt"><b>Lesson:</b> {lesson} </p> 
      <p class="txt"><b>Score:</b> {score}</p> 
    </div> 
    <div class="lesson"> 
      <p class="txt"><b>Lesson:</b> {lesson} </p> 
      <p class="txt"><b>Score:</b> {score}</p> 
    </div> 
    <div class="lesson"> 
      <p class="txt"><b>Lesson:</b> {lesson} </p> 
      <p class="txt"><b>Score:</b> {score}</p> 
    </div> 
    <div class="lesson"> 
      <p class="txt"><b>Lesson:</b> {lesson} </p> 
      <p class="txt"><b>Score:</b> {score}</p> 
    </div> 
    </div> 
</div> 

CSS

#container { 
    position: relative; 
    top: 70px; 
    left: 80px; 
    width:100%; 
    height:80%; 
} 

#first { 
    background-color: #A1D490; 
    width:45%; 
    height:100%; 
    float:left; 
    border:2px solid black; 
    margin: 5px; 
} 

.lesson { 
    position: relative; 
    background-color: #DCDDDE; 
    margin:10px; 
    width:200px; 
    height:200px; 
    border:1px solid; 
    text-align: center; 
} 
+0

不,我没有覆盖任何东西..在HTML索引中它是唯一的一个CSS文件despit引导(但仍然名称不同) –

+0

而这个codepen不会移动到下一列其他容器,它只是扩展主货柜/ –