Bootstrap按钮组中mr-2、mb-3的作用是什么?离线如何查询?
Understanding Bootstrap's
mr-2 and mb-3 Classes Hey Anna, great questions—let's unpack this step by step!
What do mr-2 and mb-3 actually do?
These are part of Bootstrap's spacing utility classes—a set of pre-built classes that let you add margin/padding without writing custom CSS. They follow a straightforward naming rule:
- The first letter (
mhere) = margin (usepif it's padding) - The second letter (
rformr-2,bformb-3) = direction:t= top,b= bottom,l= left,r= right,x= left+right,y= top+bottom
- The number (2 or 3) = a predefined spacing value from Bootstrap's scale. By default:
2translates to0.5rem(8px)3translates to1rem(16px)
Applying this to your code:
mr-2on the.btn-groupadds 0.5rem of right margin to the button group, creating space between it and the next element in the toolbar.mb-3on the.btn-toolbaradds 1rem of bottom margin to the entire toolbar, so any content below it gets pushed down by that amount.
How to look up these classes offline
You don't need an internet connection to figure this out—here are three solid methods:
- Check Bootstrap's local CSS file
If you downloaded Bootstrap's source files (instead of using a CDN), openbootstrap.cssorbootstrap.min.cssand search for the class name. You'll see the exact CSS rules, like:.mr-2 { margin-right: 0.5rem !important; } - Use Bootstrap's offline documentation
When you have internet, download Bootstrap's full package (including docs) from their site. Unzip it, and you can open theindex.htmlin thedocsfolder anytime offline. The utility classes section covers spacing, colors, and all other helper classes in detail. - Memorize the naming convention
Bootstrap's utility classes follow consistent patterns. Once you get the hang of the spacing rule ([m/p][direction]-[scale-number]), you can guess what most classes do without looking them up. The scale numbers 0-5 map to 0, 0.25rem, 0.5rem, 1rem, 1.5rem, and 3rem by default.
内容的提问来源于stack exchange,提问作者Anna Klein
相关产品推荐
相关产品推荐

