Bootstrap 3导航栏底部边框出现间隙问题求助
Hey Brian, I’ve dealt with this exact frustrating issue before when customizing Bootstrap 3 navbars—those tiny gaps can drive you crazy! Let’s walk through what’s probably causing it and how to fix it.
Common Causes & Solutions
1. Box Sizing Mismatch
The most likely culprit is that your height: 110px setting doesn’t account for the 1px bottom border. By default, browsers use content-box box sizing, which means the border adds to the element’s total height. This leaves the navbar’s background only covering the 110px content area, while the border sits below it—creating that visible gap.
Fix: Add box-sizing: border-box to your custom navbar CSS. This forces the border to be included within the 110px height, so the background extends all the way to the bottom of the border:
.navbar-custom { height: 110px; box-sizing: border-box; /* Critical line */ background: linear-gradient(to bottom, #your-start-gradient, #your-end-gradient); border-bottom: 1px solid #your-border-color; }
2. Subpixel Rendering Glitch
Sometimes even with correct box sizing, browser subpixel rendering can create a tiny gap between the gradient background and the border. This happens because gradients are rendered as images, and the browser might not align them perfectly with the solid border.
Fix: Tweak your gradient to end with a 1px segment matching your border color. This fills in any rendering gaps:
.navbar-custom { background: linear-gradient(to bottom, #your-start-gradient 0%, #your-end-gradient 99%, #your-border-color 100%); }
Alternatively, add a subtle box shadow that matches your border color to cover the gap:
.navbar-custom { box-shadow: 0 1px 0 #your-border-color; }
3. Bootstrap’s Default Box Shadow
Bootstrap 3 navbars come with a default box-shadow (usually something like 0 1px 0 rgba(255,255,255,.1)). This shadow can sometimes conflict with your custom border, creating a visual gap.
Fix: Override the default shadow by setting it to none:
.navbar-custom { box-shadow: none; }
Final Notes
I’ve used these exact fixes on several Bootstrap 3 projects, and they’ve consistently resolved that annoying 1px gap. Start with the box-sizing fix first—it’s the most common solution. If that doesn’t work, try the gradient tweak or shadow adjustment.
内容的提问来源于stack exchange,提问作者Brian Williams

