CSS显示:表格单元格宽度100%overflow-x展开

时间:2015-11-05 11:54:00

标签: css responsive-design scrollbar html-table

我有这两个列布局,用display:table和display:table-cell制作,我想在第二列放一个带水平滚动的div,但是表格会自动展开,滚动会转到整个页面而不是div。

HTML

<div class="wrapper">
    <div id="one"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque convallis finibus metus. Suspendisse commodo rutrum sapien, eu faucibus metus. Nunc elementum augue eu aliquet condimentum. 
    </div>
    <div id="two">
        <div id="horizontal">
            <img src="https://dl.dropbox.com/u/1218282/slideshow/1.jpg" />
            <img src="https://dl.dropbox.com/u/1218282/slideshow/2.jpg" />
            <img src="https://dl.dropbox.com/u/1218282/slideshow/3.jpg" />
            <img src="https://dl.dropbox.com/u/1218282/slideshow/4.jpg" />
        </div>        
   </div>        
</div>

CSS

.wrapper { 
    display: table;
    table-layout: fixed;
}
#one {
    display: table-cell;
    background-color: gray;
    width: 200px;
}
#two { 
    display: table-cell;
    width: 100%;
}
#horizontal {
    width: 100%;
    overflow-x: scroll;
    white-space: nowrap;
}
#horizontal img {
     max-width: 200px;   
}

这是jsfiddle: http://jsfiddle.net/cUCvY/2597/

在这个例子中,我希望在div上激活水平滚动,图像在里面而不在页面上。

1 个答案:

答案 0 :(得分:1)

希望我理解正确:

.wrapper { 
    display: table;
    table-layout: fixed;
    width:100%
}
#one {
   display: table-cell;
    background-color: gray;
    width: 200px;
}
#two { 
}
#horizontal {

    overflow-x: scroll;
    white-space: nowrap;
}
#horizontal img {
     max-width: 200px;   
}
}

@media screen and (max-width: 400px) {
   #one { 
    float: none;
    margin-right:0;
    width:auto;
    border:0;
    border-bottom:2px solid #000;    
  }
}

http://jsfiddle.net/cUCvY/2600/