简体   繁体   English

Bootstrap v4推拉网格类未按预期运行

[英]Bootstrap v4 push and pull grid classes aren't working as expected

I am trying to use Bootstrap v4 (alpha 3) to create a responsive layout for a web application that i'm working on. 我正在尝试使用Bootstrap v4(alpha 3)为我正在处理的Web应用程序创建响应式布局。

Everything works for the most part but what i'm really struggling with is reordering my cards using the push and pull classes. 大部分情况下一切正常,但是我真正挣扎的是使用push和pull类对卡进行重新排序。 It was to my understanding that the push and pull classes reordered the cards when used correctly while the rest of the layout responded to the change of order as mentioned in the Grid system section of the docs under 'column ordering': 据我了解,正确使用push和pull类会对卡片进行重新排序,而布局的其余部分则响应文档的“列排序”下“网格系统”部分中提到的顺序更改:

Easily change the order of our built-in grid columns with .push-md-* and .pull-md-* modifier classes. 使用.push-md- *和.pull-md- *修饰符类轻松更改内置网格列的顺序。

which can be found here: http://v4-alpha.getbootstrap.com/layout/grid/#example-column-ordering 可以在这里找到: http : //v4-alpha.getbootstrap.com/layout/grid/#example-column-ordering

However, when using these classes it seems to, instead of reordering the cards, just move them left and right (to the point where they can even overlap or go off screen, this functionality is also suggested by their css). 但是,当使用这些类时,似乎并不需要重新排序卡,而只是左右移动它们(以至于它们甚至可以重叠或离开屏幕,它们的CSS也建议使用此功能)。 This also implies that they have the exact same functionality as the offset functions, who's purpose is to move a card by x number of columns. 这也意味着它们具有与偏移功能完全相同的功能,其目的是将卡移动x列数。

I have managed to get them working as expected in the past before, but have no idea how. 我过去曾经设法使它们按预期工作,但不知道如何工作。 So can someone please tell me what i'm doing wrong? 所以有人可以告诉我我在做什么错吗?

HTML: HTML:

<div class="container">
    <div class="row">   
       <div class="card card1 col-lg-4 col-md-6"></div>
       <div class="card card2 col-lg-4 col-md-6"></div>
       <div class="card card4 col-lg-8 col-md-12 push-lg-4"></div>
       <div class="card card3 col-lg-4 col-md-6 pull-lg-8"></div>        
    </div>
</div>

CSS: CSS:

.card{height: 150px;}
.card1{background-color:red;}
.card2{background-color:blue;}
.card3{background-color:green;}
.card4{background-color:yellow;}

JSFIDDLE: https://jsfiddle.net/61yoqkjk/5/ JSFIDDLE: https ://jsfiddle.net/61yoqkjk/5/

The expected behavior is that at large sizes and higher, the green box will be moved up to be on the same line as the red and blue boxes. 预期的行为是,在大尺寸或更高尺寸的情况下,绿色框将向上移动,与红色框和蓝色框位于同一行。 However, instead the green and yellow boxes swap places but there's now a gap to the right of the blue box where the green box could fit. 但是,相反,绿色和黄色的框会交换位置,但是蓝色框的右边现在有一个适合绿色框的间隙。

This has been tried with Bootstrap 3 as well so I don't think this is a bug. Bootstrap 3也对此进行了尝试,因此我认为这不是错误。 I have also checked through other similar questions but none of their answers seem to fix my problem. 我也检查了其他类似的问题,但他们的答案似乎都无法解决我的问题。

I think you might be misunderstanding, how bootstrap works. 我认为您可能会误解引导程序的工作原理。 You want, that the elements some sort of "switch their position" by pulling/pushing them (which is very hard to achieve with css only). 您希望元素通过拉/推某种方式“切换其位置”(仅使用css很难实现)。 What bootstrap does, instead, is that the helper classes push-xx and pull-xx move the elements visually around. 相反,引导程序所做的是帮助程序类push-xx和pull-xx在视觉上移动元素。 Eg the code for pull-lg-8 is: 例如pull-lg-8的代码是:

.pull-lg-8 {
    right: 66.666667%;
}

...and this does NOT affect the other elements. ...并且这不会影响其他元素。 Imagine, that the browser first calculates the layout box for each element by using properties like width, height, float, display, ... and afterwards, after every element has a certain place where it belongs, the relative positioned elements are visually moved to a different place (if right, top, bottom or left was used). 想象一下,浏览器首先通过使用诸如width, height, float, display, ...等属性来计算每个元素的布局框,然后在每个元素都有其所属的特定位置之后,将相对定位的元素视觉上移至一个不同的位置(如果使用的是right, top, bottom or left )。 From a structural point of view, they still take the same space, though and don't affect the other elements. 从结构的角度来看,它们仍然占据相同的空间,并且不会影响其他元素。

Therefore your yellow element (which is too big for the first line) is in the second row taking 2/3 of the space, whereas your green element has its box in the second row at the very right and is afterwards pushed 2/3 to the left. 因此,您的黄色元素(对于第一行来说太大了)位于第二行,占据了2/3的空间,而您的绿色元素在第二行的右边具有其框,然后将其推向2/3以左边。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM