内联块元素的水平滚动

时间:2014-04-23 04:53:42

标签: html css

我有内联阻止div但是当它们到达屏幕的末端时,它们会转到下一行而不是水平滚动,有人可以帮助我吗? 这是一个fiddle

<div class="m_wrap">
<div class="dx">
    <div class="xc">1</div>
    <div class="xc">2</div>
    <div class="xc">3</div>
    <div class="xc">4</div>
    <div class="xc">5</div>
    <div class="xc">6</div>
    <div class="xc">7</div>
    <div class="xc">8</div>
    <div class="xc">9</div>
    <div class="xc">10</div>

   </div>
  </div>

CSS

.m_wrap{
width:100%;
height:100px;
}
.dx{
   width:100%;
height:100px;
overflow:scroll;
}
.xc{
display:inline-block;
width:100px;
height:80px;
border:1px solid;
line-height:80px;
text-align:center;
margin-bottom:4px;
 }

3 个答案:

答案 0 :(得分:33)

white-space: nowrap;课程上使用dx

Fiddle

.dx{
    width:100%;
    height:100px;
    overflow:scroll;
    white-space: nowrap;
}

答案 1 :(得分:1)

隐藏y溢出并使用nowrap

.dx {
    height: 100px;
    overflow-y: hidden;
    white-space: nowrap;
    width: 100%;
}

<强> FIDDLE

答案 2 :(得分:1)

使用 transform 进行更多最新的解决方案怎么样?

HTML

<div class="horizontal-scroll-wrapper">
  <div>item 1</div>
  <div>item 2</div>
  <div>item 3</div>
  <div>item 4</div>
  <div>item 5</div>
  <div>item 6</div>
  <div>item 7</div>
  <div>item 8</div>
  <div>item 9</div>
  <div>item 10</div>
</div>

CSS

div {
  box-sizing: border-box;
}

.horizontal-scroll-wrapper {
  background: #abc;
  display: block;
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 60px;
  position: absolute;
  transform: rotate(-90deg) translateY(-80px);
  transform-origin: right top;
}

.horizontal-scroll-wrapper > div {
  background: #cab;
  height: 60px;
  margin: 10px;
  padding: 5px;
  transform: rotate(90deg);
  transform-origin: right top;
  width: 60px;
}

CodeSandbox,受到https://css-tricks.com/pure-css-horizontal-scrolling/的启发

相关问题