You need to enable JavaScript to run this app. 使用Bootstrap时面包屑导航与搜索栏无法对齐怎么解决
优惠活动
大模型
产品
解决方案
定价
更多

使用Bootstrap时面包屑导航与搜索栏无法对齐怎么解决

问题原因

  • 仅右侧搜索栏所在列设置了my-auto垂直居中类,左侧面包屑列没有对应垂直对齐配置
  • Bootstrap默认的.breadcrumb组件自带margin-bottom: 1rem的默认样式,会额外占据垂直空间,导致上下错位

修复代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

</head>
<body>
    <div class="container" style="background-color: red;">
        <div class="row marginTop">
            
            <div class="col-md-4 my-auto">
                <nav aria-label="breadcrumb">
                  <ol class="breadcrumb bg-dark mb-0"><!--transparent-->
                    <li class="breadcrumb-item "><a href="#">Test1</a></li>
                    <li class="breadcrumb-item"><a href="#">Test2</a></li>
                    <li class="breadcrumb-item"><a href="#">Test3</a></li>
                  </ol>
                </nav>
            </div>
            
            <div class="col-md-4 ml-auto my-auto" style="background-color: black;">
                <form class="d-flex">
                    <input class="form-control mr-1" type="search" placeholder="Search..." aria-label="Search">
                    <button class="btn btn_rechercher" type="submit">Search</button>
                </form>     
            </div>

        </div>  
    </div>
</body>
</html>

修改说明

  1. 给左侧面包屑容器列新增my-auto类,和右侧搜索栏保持相同的垂直居中规则
  2. 给面包屑列表新增mb-0类,清除组件默认自带的下外边距,避免额外撑高容器导致错位

内容的提问来源于stack exchange,提问作者Balaure

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.11 10:36:02