Bootstrap 4中.col与.col-xs/sm/md/lg-6的区别及元素换行问题咨询
Hey there! Let's break this down clearly for you—Bootstrap's grid can trip up even experienced devs sometimes, so no worries asking about this.
.col and .col-{breakpoint}-6 in Bootstrap 4 Let's start with the core distinctions between these two column classes:
.colis an auto-layout column- It’s part of Bootstrap’s flexbox-powered "auto columns" system. Any
.colelements inside the same.rowwill split the available row width equally (3.cols = each takes 1/3 of the row, 4 = 1/4, etc.). - It has no breakpoint specified, so this equal-width behavior stays consistent across all screen sizes—from tiny mobile (xs) up to large desktops (lg).
- It’s part of Bootstrap’s flexbox-powered "auto columns" system. Any
.col-{breakpoint}-6is a responsive fixed-width column- The
-6means this column takes up 6 out of Bootstrap’s 12 grid columns (aka 50% of the row’s width) at the specified breakpoint and above. - It’s inherently responsive: for example,
.col-md-6will take 50% width on medium screens and larger, but stack to 100% width on smaller screens unless you add a smaller breakpoint class (like.col-sm-6). - Unlike
.col, this class explicitly defines a fixed width ratio at specific screen sizes, rather than auto-splitting available space.
- The
.col Wraps to the Next Line? Looking at your code snippet, you only have one .col in the .row—but based on your question, I assume you actually have three .col elements inside that same .row (easy typo when pasting code!).
The most common culprit here is content inside your .col breaking the flex layout—specifically, your image isn’t set to be responsive. Bootstrap’s .row uses flexbox, which lets .cols split space equally by default, but if an element inside a .col (like your image) has a fixed width larger than the column’s available space, it’ll stretch the column wider than its intended share. When the total width of all three columns exceeds the .row’s width, the last column wraps to the next line (since .row has flex-wrap: wrap enabled by default).
Fixes to Try:
- Make your image responsive with Bootstrap’s built-in
.img-fluidclass. This forces the image to max out at 100% of its parent container’s width, so it won’t stretch the column:<img src="http://qlip.in/images/YMCA-Realtor-Donation-3.jpg" class="img-fluid"> - Double-check your nesting: Bootstrap requires columns to be direct children of a
.row—if you added extra divs around your.colelements that aren’t part of Bootstrap’s grid system, that could throw off the layout. - Verify no custom CSS is overriding Bootstrap styles: If you have custom styles that change
flex-grow,flex-shrink, orwidthon.color.row, that could disrupt the auto-layout behavior.
内容的提问来源于stack exchange,提问作者bkirklint




