如何使用Bootstrap 3更改元素的显示顺序

时间:2013-10-03 10:46:25

标签: twitter-bootstrap twitter-bootstrap-3 elements

有人可以帮助我我想我怎么能用引导程序做这个,有人有线索吗?我不知道你怎么能改变元素的显示顺序,我猜它可以用浮动和清除来玩。 请帮助我需要帮助。 我使用Bootstrap 3作为响应式布局,如何仅使用css更改显示顺序?

enter image description here

1 个答案:

答案 0 :(得分:0)

@skelly是对的,您可以使用push和pull类来更改元素的显示顺序。这些课程总是不能为您提供正确的解决方案。

还有许多其他问题,例如:Need to be able to swap grid on mobile

因为您想要在移动(xs网格)/平板电脑视图(md网格)中更改100%宽度的行(黄色行),您无法通过浮动和/或推拉来解决此问题。

我也相信只有在不修复某些参数的情况下才能使用CSS。

当我考虑一些已知/固定不同视图的元素的高度时,我可以使用css和媒体查询来解决它:http://bootply.com/85303

<强> CSS

@media (max-width: 768px)
{
.yellow {margin-top:-60px;}
.orange {margin-top:40px;}
.col-xs-12{float:left;}
}
@media (min-width: 992px) and (max-width:1199px)
{
    .col-md-12 {float:left;}
    .darkgreen{float:right; margin-top:-60px;}
}   
@media (min-width: 1200px)
{
.blue{margin-top:-60px}
}

<强> HTML

<div class="container">
    <div class="row">
        <div class="col-lg-12 col-md-12 col-xs-12" style="background-color:red;">&nbsp;</div>
    </div>

    <div class="row">
    <div class="orange col-lg-12 col-md-8 col-xs-12" style="background-color:orange;">&nbsp;</div>
    <div class="yellow col-lg-8 col-md-12 col-xs-12" style="">
    <div class="row">
        <div class="col-lg-6 col-xs-12" style="background-color:yellow;height:40px;">1</div>
        <div class="col-lg-6 visible-lg" style="background-color:yellow;height:40px;">2</div>
        <div class="col-lg-6 visible-lg" style="background-color:yellow;height:40px;">3</div>
        <div class="col-lg-6 visible-lg" style="background-color:yellow;height:40px;">4</div>
    </div>  
    </div>
    <div class="darkgreen col-lg-4 col-md-4 col-xs-12" style="background-color:darkgreen;">&nbsp;</div> 
    <div class="pink col-lg-8 col-md-12 col-xs-12" style="background-color:pink;">&nbsp;</div>
    <div class="blue col-lg-4 col-md-12 col-xs-12" style="background-color:blue;height:40px;">&nbsp;</div>  
    </div>

</div>

注意通过添加(负)上边距来更改某些元素。只有当我知道他们的身高时,我才能这样做。另请注意我添加了一个浮点数:左col-xs-12col-xs-12

在您不知道高度的实际情况中,您可以尝试使用javascript计算它(使用respond.js进行媒体查询)并添加顶部边距。我不知道这是否会为您提供更好的解决方案,然后当您使用jQuery操作DOM时,请参阅:Add new row and changing column classes on resize

相关问题