Bootstrap 3 栏居中 responsive centered columns

An easy solution to center multiple columns in Bootstrap 3, also on mobile

The Problem

Sometimes you want to center Bootstrap columns, usually when you have an uneven number of them, or when you give them a max-width and they don’t fill up the containing row.

The Solution

The Markup

Just add the class .row-centered to the row and .col-centered to the columns.

<div class="container">
    <div class="row row-centered">
        <div class="col-xs-6 col-centered"></div>
        <div class="col-xs-6 col-centered"></div>
        <div class="col-xs-3 col-centered"></div>
        <div class="col-xs-3 col-centered"></div>
        <div class="col-xs-3 col-centered"></div>

The Css

This simple css code centers the columns (.col-centered) inside the row (.row-centered).

/* centered columns styles */
.row-centered {
.col-centered {
    /* reset the text-align */
    /* inline-block space fix */

You can also set a min-width, a max-width or a fixed width to the columns.

.col-fixed {
    /* custom width */
.col-min {
    /* custom min width */
.col-max {
    /* custom max width */

IE8 Support

The code works also on IE8 only if you make Bootstrap 3 work on IE8. To make it work you need to use Respond.js and follow the respond.js guidelines:

  • Change the Bootstrap 3 Css to a local file: Respond.js only works with local Css files unless additional steps are taken.
  • Change the Css from a style element to an external local Css with link rel=”stylesheet”: Respond.js doesn’t parse Css referenced via @import, nor does it work with media queries within style elements.
  • Reference the Respond.js script after all of your Css.



本文:Bootstrap 3 栏居中 responsive centered columns


Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.