I have inline-block divs however when they reach end of the screen, they go the next line instead of scrolling horizontally, can someone help me out? here is a 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;
}
For horizontal scrollable bar use the x and y-axis. Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line.
To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.
The overflow-inline CSS property sets what shows when content overflows the inline start and end edges of a box. This may be nothing, a scroll bar, or the overflow content. Note: The overflow-inline property maps to overflow-y or overflow-x depending on the writing mode of the document.
Web browsers do not take into account the width of the scrollbar on the side of a page when computing width values, so since we have a page that is longer than a single viewport, part of our page is being rendered behind the vertical scroll bar, causing the browser to display a horizontal scroll bar.
Use white-space: nowrap;
on dx
class.
Fiddle
.dx{
width:100%;
height:100px;
overflow:scroll;
white-space: nowrap;
}
Hide the y overflow and use nowrap
.dx {
height: 100px;
overflow-y: hidden;
white-space: nowrap;
width: 100%;
}
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With