官术网_书友最值得收藏!

  • Bootstrap Site Blueprints
  • David Cochran Ian Whitley
  • 417字
  • 2021-07-16 12:27:40

Creating responsive columns

We have three blocks of text, each with a heading, a short paragraph, and a link. In screen sizes of approximately tablet width or more, we would like this content to be laid out in three columns. In narrower screen widths, the content will organize itself in one full-width column.

Take a moment to visit and read the documentation for Bootstrap's mobile-first responsive grid. You can find it at http://getbootstrap.com/css/#grid.

In short, the grid is based on a twelve-column system. The basic class structure allows us to use a class of col-12 for full-width, col-6 for half-width, col-4 for one-third width, and so on.

With Bootstrap 3, thanks to the creative use of media queries, Bootstrap's grid can be very adept. Recall that we want our welcome message to have a single-column layout up to tablet-sized screens, and then adapt a three-column layout at approximately 768px. Conveniently, Bootstrap has a built-in breakpoint at 768px, which is the default value of its @screen-sm-min variable. Above 768px is the medium range beginning at 992px, corresponding to a @screen-md-min variable, then the large screen, beginning at 1200px and up. I'll refer to these as Bootstrap's small, medium, and large breakpoints.

With the small breakpoint there is a special column class that uses the formulation col-sm-. Because we want three columns after the small breakpoint, we'll use class="col-sm-4". Below the small breakpoint, the elements will remain full-width. Above it, they will shift to 1/3 width and line up side by side. The full structure is given here, with paragraph contents abbreviated for clarity:

<div class="container">
  <div class="row">
    <div class="col-sm-4">
    <h2>Welcome!</h2>
    <p>Suspendisse et arcu felis ...</p>
    <p><a href="#">See our portfolio</a></p>
  </div>
  <div class="col-sm-4">
    <h2>Recent Updates</h2>
    <p>Suspendisse et arcu felis ...</p>
    <p><a href="#">See what's new!</a></p>
  </div>
  <div class="col-sm-4">
    <h2>Our Team</h2>
    <p>Suspendisse et arcu felis ...</p>
    <p><a href="#">Meet the team!</a></p>
  </div>
  </div><!-- /.row -->
</div><!-- /.container -->

If you're unfamiliar with the container and row classes, here is what they do:

  • The container class constrains the width of the content and keeps it centered within the page
  • The row class provides the wrapper for our columns, allowing extra left and right margin for the column gutters
  • Both the container class and the row class are clearfixed, so that they contain floating elements and clear any previous floating elements

Now, save and refresh. With your browser width above 768px, you should see the following three-column layout take shape:

Creating responsive columns

Resize your browser window below 768px, and you'll see it revert to a single column.

Creating responsive columns

With our responsive grid in place, let's turn those links into clearly visible calls to action by utilizing Bootstrap's button styles.

主站蜘蛛池模板: 揭西县| 承德市| 长岛县| 五峰| 长春市| 康保县| 韩城市| 昂仁县| 韶山市| 庄河市| 安新县| 华阴市| 霞浦县| 皋兰县| 昭觉县| 合川市| 济南市| 黄冈市| 霍州市| 江川县| 双城市| 丹巴县| 武强县| 增城市| 乐都县| 新沂市| 元谋县| 枞阳县| 简阳市| 通道| 乐都县| 新河县| 睢宁县| 建湖县| 关岭| 太原市| 民县| 邹城市| 阳朔县| 吉水县| 丰城市|