Reputation: 149
I am developing a layout with bootstrap and some flex containers and can't seem to find out why my box would always grow larger than its container. I created a fiddle to illustrate the problem: example fiddle .
The html part looks like this:
<div class="container-fluid overflow-hidden">
<div class="row flex-nowrap">
<div class="col const-width">
const
</div>
<div class="col">
<div class="bigcontent">
some very very very very very very very very very very very big content
</div>
</div>
<div class="col const-width">
const
</div>
</div>
</div>
And the css is the following:
.const-width {
max-width: 100px !important;
min-width: 100px !important;
}
.bigcontent {
background: #aaaaaa;
white-space: nowrap;
}
As you can see, I have two constant width boxes on the sides and a flexible box that should take up the rest of the space between the other two. If the content of the flexible-width box grows too big, the rightmost box get's pushed off-screen. What I want instead is, that the content of the flexible-width box gets scrollable and everything remains on-screen.
I tried this by wrapping the content in another div, but couldn't get it to work.
Any help is appreciated! :)
Upvotes: 1
Views: 57
Reputation: 8162
Look like this?
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
overflow-x:auto!important;
}
.const-width {
max-width: 100px !important;
min-width: 100px !important;
}
.bigcontent {
background: #aaaaaa;
min-width: 500px;
white-space: nowrap;
}
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="container overflow-hidden">
<div class="row flex-nowrap">
<div class="col const-width">
const
</div>
<div class="col ">
<div class="bigcontent">
some very very very very very very very very very very very very very very very very big content
</div>
</div>
<div class="col const-width">
const
</div>
</div>
</div>
I delete scroll div and apply overflow-x to .col class auto with !important rule
Upvotes: 2