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

Bootstrap移动端网格失效:.col-xs-3表现为全屏(同.col-xs-12)求解决思路

Troubleshooting Bootstrap Mobile Grid Not Working (.col-xs-3 Acting Like .col-xs-12)

Hey there, let’s dig into why your mobile columns are stretching full-width instead of behaving as expected. Here are the most common fixes to check:

  • Verify your Bootstrap version first
    This is the #1 culprit! Bootstrap 4 and 5 removed the xs prefix for mobile-first columns. If you’re using Bootstrap 4+, .col-xs-3 isn’t a valid class—so the browser treats the div as a default block element (which takes 100% width, just like .col-xs-12 would in Bootstrap 3).
    Fix: Replace .col-xs-3 with .col-3 for mobile columns. Your updated code would look like this:

    <div class="container">
      <div class="row">
        <div class="col-md-1 col-3">
          <a href="#">
            <img src="/.." />
          </a>
        </div>
        <div class="col-md-1 col-3">
          <a href="#">
            <img src="/.." />
          </a>
        </div>
        <div class="col-md-1 col-3">
          <a href="#">
            <img src="/.." />
          </a>
        </div>
        ...
      </div>
    </div>
    
  • Ensure Bootstrap CSS is properly loaded
    If you’re using Bootstrap 3 (where .col-xs-3 is valid), double-check that you’ve included the Bootstrap CSS file correctly in your page’s <head>. A missing or mislinked CSS file means none of the grid styles will apply, so all columns will default to full width.
    Tip: Open your browser’s dev tools (F12), go to the Elements tab, inspect the .col-xs-3 div, and check if the Bootstrap grid styles (like width: 25%; float: left; for .col-xs-3) are present. If not, your CSS isn’t loading.

  • Check for conflicting custom CSS
    Sometimes custom styles can override Bootstrap’s grid rules. Look for any CSS that targets .col-xs-3, or even parent elements like .row or .container, that might be setting width: 100%, display: block, or overriding float properties.
    For example, if you have something like this in your custom CSS, it’ll break the grid:

    .col-xs-3 {
      width: 100% !important;
    }
    

    Use dev tools to audit the computed styles for the column element to spot these overrides.

  • Confirm your grid structure is correct
    Make sure your .row is directly nested inside a .container or .container-fluid—Bootstrap’s grid relies on this hierarchy for proper padding and margin handling. Avoid wrapping .row in other containers that add unexpected padding or width constraints, as this can throw off the column calculations.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:50:05