chris Frisina
chris Frisina

Reputation: 19688

Overflow-x scroll only on a parent div with a fixed height and unknown number of children

If I have a parent and child div:

<div class="parent">
    <div class="content child">1</div>
</div>

The parent div has:

The content children will be:

What CSS is needed on the parent, and each child?

Here is a fiddle with my best attempt.

Upvotes: 0

Views: 3201

Answers (2)

mvaldetaro
mvaldetaro

Reputation: 172

Using flexbox:

.parent {
    display: flex;
    overflow-x: scroll;
}

.content {
    display: block;
}

Upvotes: 0

omma2289
omma2289

Reputation: 54629

To have all elements in a single line you need to make the child elements display inline-block and disable wrapping of white space on the parent

.parent {
    max-width: 50%;
    overflow-x: scroll;
    white-space: nowrap;
}

.content {
    display: inline-block;
}

Example fiddle

Upvotes: 6

Related Questions