问题
I'm currently using Bootstrap 3.3.7 and because my site is huge it isn't easy to migrate to v4. Nevertheless I'd like to use the new Auto-Layout-columns (Variable width content) feature (see screenshot below).
Has anybody an idea for a workaround?
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-xs-push-3 col-md-3">Fixed 250px</div>
<div class="col-xs-6 col-xs-pull-3 col-md-3">Auto</div>
<div class="col-xs-6 col-md-3">Auto</div>
<div class="col-xs-6 col-md-3">Auto</div>
</div>
</div>
回答1:
You could add the flexbox CSS that makes the auto-layout columns work in Bootstrap 4...
CSS:
.d-flex {
display:flex;
}
.d-flex>div {
float: none;
}
.col-auto {
flex: 0 0 auto;
width: auto;
max-width: none;
}
Usage:
<div class="container">
<div class="row d-flex">
<div class="col-sm-3 bg-success">col-sm-3</div>
<div class="col-auto">col-auto</div>
<div class="col-sm-9 bg-success">col-sm-3</div>
</div>
</div>
Demo:
https://www.codeply.com/go/cTTtpuItaM
Related: Bootstrap 3.0 - Fluid Grid that includes Fixed Column Sizes
来源:https://stackoverflow.com/questions/50566265/use-variable-width-content-grid-in-bootstrap-3