简体   繁体   English

Bootstrap GRID系统可能吗?

[英]Bootstrap GRID System possible?

Good day! 美好的一天! I am trying to figure out if the scenario below is possible. 我想弄清楚下面的场景是否可行。

When it is on desktop/laptop the layout should be like this 当它在桌面/笔记本电脑上时,布局应该是这样的

<div class="col-md-3">
sidebar
</div>

<div class="col-md-9">
article
</div>

When it is on small screen the two div will switch and must be like this one 当它在小屏幕上时,两个div将切换,并且必须像这样

<div class="col-md-9">
sidebar
</div>

<div class="col-md-3">
article
</div>

Your answer is appreciated! 您的回答表示赞赏!

You can! 您可以! By adding multiple grid classes to your <div> 's you can define the size of your columns for each breakpoint. 通过向<div>添加多个网格类,您可以为每个断点定义列的大小。 In your case this might be col-xs-9 col-md-3 on the sidebar and col-xs-3 col-md-9 on the article. 在你的情况下,这可能是侧col-xs-9 col-md-3和文章中的col-xs-3 col-md-9 This would make the sidebar take up 9 out of 12 columns for the xs and sm breakpoint sizes, and 3 out of 12 columns for the md and lg breakpoint sizes. 这将使侧栏占据12列中的9列用于xssm断点大小,12列中的3列用于mdlg断点大小。

Open the following example in fullscreen to play with the breakpoints. 在全屏中打开以下示例以使用断点。

 .box { border: 1px solid #c66; background-color: #f99; } 
 <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="col-xs-9 col-md-3 box"> sidebar </div> <div class="col-xs-3 col-md-9 box"> article </div> 


From your comment I see you want the article to be on top of the sidebar for small screens. 从您的评论中我看到您希望文章位于侧边栏的小屏幕上。 This is a bit more tricky. 这有点棘手。 You need to do three things: 你需要做三件事:

  1. Develop mobile first by starting with the layout for small screens. 首先从小屏幕布局开始开发移动设备。 You need to change the order of the sidebar and article <div> . 您需要更改侧栏和文章<div>的顺序。

  2. Make sure that on small screens both the sidebar and the article take up 12 out of 12 columns by using col-xs-12 . 确保在小屏幕上,使用col-xs-12 ,侧栏和文章占据了12列中的12列。 This will make the sidebar get pushed below the article. 这将使侧边栏被推到文章下方。

  3. Note that on desktop screens the sidebar and article do appear next to eachother, but with the sidebar on the right instead of the left. 请注意,在桌面屏幕上,侧边栏和文章确实显示在彼此旁边,但侧边栏位于右侧而不是左侧。 You can change this by pulling the sidebar to the left by adding col-md-pull-9 (you need to pull it 9 columns to the left, the amount of columns that the article takes up) and pushing the article to the right by adding col-md-push-3 (you need to push it 3 columns to the right, the amount of columns that the sidebar takes up). 你可以通过添加col-md-pull-9向左拉边栏来改变这一点(你需要向左拉9列,文章占用的列数)并将文章推到右边添加col-md-push-3 (你需要向右推3列,侧栏占用的列数)。

See the updated example: 请参阅更新的示例:

 .box { border: 1px solid #c66; background-color: #f99; } 
 <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" /> <div class="col-xs-12 col-md-9 col-md-push-3 box"> article </div> <div class="col-xs-12 col-md-3 col-md-pull-9 box"> sidebar </div> 

There is few prefixes for bootstrap to specify width class: -xs- / -sm- / -md- / -lg- (from smallest to biggest width). bootstrap的前缀很少,无法指定宽度类: -xs- / -sm- / -md- / -lg- (从最小到最大宽度)。

So from -md- and bigger screen you have col-md-3 and col-md-9 . 所以从-md-和更大的屏幕你有col-md-3col-md-9 To get them in reverse order on pre- -md- class you can specify -xs- or -sm- prefix. 要在pre- -md-类中以相反顺序获取它们,可以指定-xs--sm-前缀。

So to reverse your classes, just write: 所以要反转你的类,只需写:

<div class="col-md-9 col-xs-3"></div>
<div class="col-md-3 col-xs-9"></div>

Try this: 尝试这个:

<div class="col-sm-9 col-md-3">
 sidebar
</div>

<div class="col-sm-3 col-md-9">
 article
</div>

This will display the sidebar in 9 blocks in eXtraSmall (xs) and SMall (sm) and in 3 Blocks for MeDium (md) and LarGe (lg) and vice versa. 这将在eXtraSmall(xs)和SMall(sm)中显示9个块中的侧边栏,在MeDium(md)和LarGe(lg)中显示3个块中的侧边栏,反之亦然。

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

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