【问题标题】:Have a horizontally scroll bar with a width:100% element有一个带有 width:100% 元素的水平滚动条
【发布时间】:2014-04-29 10:03:26
【问题描述】:

我的网站中有下一个 DIV(占我页面宽度的 100%):

float: left;
border: solid 2px rgb(119, 36, 98);
width: 100%;
position: relative;
margin-bottom: 10px;
background-color: #eee;
overflow-x: scroll;

我想在这个 div 中放置一个比显示的表格更大的表格(如果需要,还有一个水平滚动条)。

但如果我这样做,则不遵守规则宽度:100%

float: left;
height: 250px;
overflow-y: scroll;
width: 2000px;

有什么想法可以让我的屏幕 100% 的元素带有水平滚动条吗?

【问题讨论】:

标签: html css


【解决方案1】:

Demo

<div id="scroll">
    <img src="http://thinkingstiff.com/images/priorities.png" />
</div>


html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    width: 100%;
}

#scroll {
    height: 100%;
    overflow-x: scroll;    
    white-space: nowrap;
    width: 100%;
}

#scroll img {
    height: 100%;
    vertical-align: top; /* this prevents vertical whitespace */
}

【讨论】:

  • 问题是我的父 div 有“min-width:780px;border-left:solid 200px #CCC;”。如果我在其上使用 width:100%,我的全局窗口中会出现一个水平滚动条
  • calc(100% - 220px) 现在是我的朋友了
猜你喜欢
  • 2021-12-14
  • 1970-01-01
  • 1970-01-01
  • 2016-05-28
  • 2011-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-05
相关资源
最近更新 更多