Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

horizontal scroll of inline-block element

Tags:

html

css

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;
 }
like image 456
user3412305 Avatar asked Apr 23 '14 04:04

user3412305


People also ask

How do I create a horizontal scrolling container?

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.

How do I scroll horizontally in CSS?

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.

What is overflow inline?

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.

What causes horizontal scroll?

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.


2 Answers

Use white-space: nowrap; on dx class.

Fiddle

.dx{
    width:100%;
    height:100px;
    overflow:scroll;
    white-space: nowrap;
}
like image 97
JunM Avatar answered Oct 07 '22 17:10

JunM


Hide the y overflow and use nowrap

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

FIDDLE

like image 35
Orahmax Avatar answered Oct 07 '22 19:10

Orahmax