You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bootstrap中划分栅格系统?中等屏分2列、小屏分1列需求咨询

How to Set Up Bootstrap Grid: 2 Columns on Medium Screens, 1 Column on Small Screens

Hey there! Let's break down how to get this responsive grid working exactly how you want it. Bootstrap's grid system is built around mobile-first principles, so we can use its built-in classes to handle the different screen sizes easily.

Core Concept

Bootstrap uses a 12-column layout. For medium screens (md, starting at 768px wide), we want each column to take up half the row — that's 6 out of 12 columns. For small screens (sm, below 768px), each column should span the full row width, which means 12 columns.

Working Code Example

<div class="container">
  <div class="row">
    <!-- First Column -->
    <div class="col-md-6 col-sm-12">
      Your first column content goes here!
    </div>
    <!-- Second Column -->
    <div class="col-md-6 col-sm-12">
      Your second column content goes here!
    </div>
  </div>
</div>

Class Breakdown

  • col-md-6: On medium-sized screens and larger (≥768px), this element takes up 6 of the 12 available columns. Two of these will fit side-by-side, creating your 2-column layout.
  • col-sm-12: On small screens and smaller (<768px), this element spans all 12 columns, making each column stack vertically into a single-column layout.

Quick Simplification Tip

Since Bootstrap is mobile-first, you could skip the col-sm-12 class entirely and just use col-md-6. By default, any column class without a smaller screen size specified will automatically stack to full width on smaller screens. Adding col-sm-12 just makes your layout intent clearer for anyone reading your code later — totally optional but helpful for readability!

内容的提问来源于stack exchange,提问作者ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:59:04