bootstrap 4动画列宽变化

时间:2017-03-23 15:00:35

标签: css twitter-bootstrap bootstrap-4 twitter-bootstrap-4

我有两个这样的列:

<div class="container">
    <div class="row">
        <div class="col-9"></div>
        <div class="col-3"></div>
    </div>
</div>

我通过angular将类名转换为col-8 offset-2col-0col-0width:0;margin:0;padding:0

我想知道如何设置列的宽度和位置的动画。

2 个答案:

答案 0 :(得分:10)

由于Bootstrap 4使用flexbox,因此CSS转换动画不起作用,除非您在列上使用设置数字flex-growflex-shrink

.col-8 {
  flex-grow: 1;
  transition: all 400ms ease;
}

.col-0 {
  width: 0; 
  flex-shrink: 1;
  transition: all 400ms ease;
}

演示:http://www.codeply.com/go/4Un0Q8CvkQ

要在网格列更改媒体查询断点(而不是通过jQuery切换类)时为其设置动画,您只需在网格列上使用CSS转换。

.row [class*='col-'] {
    transition: all 0.5s ease-in-out;
}

演示:https://www.codeply.com/go/IHUZcvNjPS

答案 1 :(得分:1)

我通过使用Bootstrap提供的列大小来更改了colmn大小。 例如col-2到col-1 然后我将过渡调整为仅针对特定类型

.row [class*='col-'] {
    transition: flex 0.5s ease-in-out, max-width .5s ease-in-out;
}
相关问题