html - 防止 float 列在另一列下换行

标签 html css

我的笔:http://codepen.io/helloworld/pen/NPwGGG?editors=110
jsFiddle:http://jsfiddle.net/dsf6tm4j/

当您调整窗口大小时,带有超链接的右栏会换到左栏下。

我怎样才能防止这种情况发生?

HTML

<div>
<div class="panel">
  <div class="panel-header">Customers</div>
  <div class="panel-body">
      <div class="panel-body-container">
          <div style="background:yellow;" class="col-2 imageContainer">
              <img  src="http://s16.postimg.org/tqs90puwl/customer.png"></img>
          </div>

      <div   class="col-2">
        <ul>
          <li class="list-group-item"><a href="#">1Intel superior solutions finder</a></li>     
          <li class="list-group-item"><a href="#">2Intel superior solutions finder</a></li>
          <li class="list-group-item"><a href="#">3Intel superior solutions finder</a></li>
        </ul>
      </div>
    </div>
    <div class="clearfix"></div>
  </div>
</div>
<div class="panel">
  <div class="panel-header">Personal Links</div>
  <div class="panel-body">body</div>
</div>
<div class="panel">
  <div class="panel-header">Events</div>
  <div class="panel-body">body</div>
</div>
   <div class="clearfix"></div>
</div>

CSS

 body, html{
  padding:0;
  margin:0;
}

* {
   box-sizing: Border-box;
   webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   border-radius: 0 !important; /* Remove rounded borders from whole layout */
}

.panel-header{  
  padding:5px;
  background:navy;
  color:white;
}

.panel-body{
  padding:5px;
  background:aliceblue;
  height:200px;
  border:1px solid navy;
}

.panel{
  float:left;
  width:33%;
  background:white;
  padding:10px;
  }

.panel-body-container{
  padding:5px;

}

.list-group-item{
  border:1px solid #ddd;
}

.clearfix {  
    clear: both;
    height:1px;
    overflow:hidden;
    margin-bottom:-1px;
    line-height:1%;
    font-size:0px;
}

.col-2{  
  float:left;
  width:50%;
}

ul
{
  list-style-type:none;
  padding:0 0 0 10px;
  margin:0;
}

ul li a{
  text-decoration:underline;  
  word-break: break-all;
}

.imageContainer {
    width: 150px;
    height: 150px;    
    overflow: hidden;
    background: #ccc;   
    text-align: center;
    line-height: 150px;
}
.imageContainer img {
    max-width: 100%;
    max-height: 100%;

}

最佳答案

看起来是因为您在 .imageContainer 上使用了特定的像素宽度。尝试将其更改为百分比:

.imageContainer {
    width: 150px; /* Change to 50% */
    height: 150px;    
    overflow: hidden;
    background: #ccc;   
    text-align: center;
    line-height: 150px;
}

关于html - 防止 float 列在另一列下换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28349480/

相关文章:

html - 我怎样才能得到溢出:scroll inside a flex box

html - 使用下拉菜单从水平导航中删除滚动条

html - Bootstrap 3.3.5 中的多级下拉列表

html - 我们怎样才能使固定左侧导航栏旁边的容器响应?

html - CSS定位

html - 无法在 Drop Down Angular Js 上显示特定数据

html - 对齐同一行上的按钮

javascript - 我需要为计算机科学制作石头剪刀布,但我需要添加蜥蜴和史波克

html - 滚动到页面外部时,让页脚保持在底部

css - 分列时使用 Flexbox 实现等高 "rows"