How can I ensure a Bootstrap column expands to fit the width of its content when this value is changed?

后端 未结 2 1540
旧巷少年郎
旧巷少年郎 2021-01-17 22:45

I have the following very simple Bootstrap grid system:

相关标签:
2条回答
  • 2021-01-17 23:33

    In Bootstrap version 4.x, you can use col-sm-auto.

    0 讨论(0)
  • 2021-01-17 23:43

    You can use Flexbox for that, making all children's width change depending on content:

    .col-sm-2 { border:1px solid; }
    
    @media screen and (min-width: 480px) {
      .flex { display: flex; flex-wrap: wrap; }
      .flex > .col-sm-2 { flex: 1; width: auto; }
    }
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <h2> RScheme </h2>
    <div class="container-fluid">
      <div class="row flex">
        <div class="col-sm-2"><img src="http://placehold.it/200x200"></div>
        <div class="col-sm-2">Arrow</div>
        <div class="col-sm-2">Compound</div>
        <div class="col-sm-2">Arrow</div>
        <div class="col-sm-2">Compound</div>
        <div class="col-sm-2">Arrow</div>
      </div>
    </div>

    jsFiddle: http://jsfiddle.net/rbxth6ac/8/

    0 讨论(0)
提交回复
热议问题