代码之家  ›  专栏  ›  技术社区  ›  Sam

在标题中嵌入Bootstrap 3导航栏

  •  -1
  • Sam  · 技术社区  · 6 年前

    在bootstrap中,我想创建一个页面标题,它由静态标题、第二行的导航栏和右侧的配置文件图片组成,如下所示:

    enter image description here

    配置文件图片的大小应固定,标题栏和导航栏的大小应相同,并应填满屏幕宽度。

    问题是,我不知道如何在css中实现这一点,尤其是因为它需要嵌入一个引导导航栏。我唯一的想法是一个老式的2x2表格,其中图片跨越两行,但表格不是用来解决布局问题的,所以肯定有更好的css方式吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   user8850199 user8850199    6 年前

    要显示全效,请观看全屏视图。

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    
        <div class="">
            <div class="row">
                <div class="col-md-11">
                    <nav class="navbar navbar-default navbar-fixed-top" style="border-radius: 5px 5px 0px 0px; border-bottom: none; border-right: 1px solid #e7e7e7; width: 91.5%">
                        <div class="container-fluid">
                            <!-- Brand and toggle get grouped for better mobile display -->
                            <div class="navbar-header">
                                
                                <a class="navbar-brand" href="#">Brand</a>
                            </div>
    
                            <!-- Collect the nav links, forms, and other content for toggling -->
                           
                        </div>
                        <!-- /.container-fluid -->
                    </nav>
    
                    <nav class="navbar navbar-default" style="margin-top: 50px; border-radius: 0px 0px 5px 5px; border-top: none">
                        <div class="container-fluid">
                           <div class="navbar-header">
                            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
                                aria-expanded="false">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                           </div>
    
                            <!-- Collect the nav links, forms, and other content for toggling -->
                            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                                <ul class="nav navbar-nav">
                                    <li >
                                        <a href="#">Link
                                            <span class="sr-only">(current)</span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#">Link</a>
                                    </li>
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown
                                            <span class="caret"></span>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a href="#">Action</a>
                                            </li>
                                            <li>
                                                <a href="#">Another action</a>
                                            </li>
                                            <li>
                                                <a href="#">Something else here</a>
                                            </li>
                                            <li role="separator" class="divider"></li>
                                            <li>
                                                <a href="#">Separated link</a>
                                            </li>
                                            <li role="separator" class="divider"></li>
                                            <li>
                                                <a href="#">One more separated link</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            <form class="navbar-form navbar-left">
                                <div class="form-group">
                                    <input type="text" class="form-control" placeholder="Search">
                                </div>
                                <button type="submit" class="btn btn-default">Submit</button>
                            </form>
                                <ul class="nav navbar-nav navbar-right">
                                    <li>
                                        <a href="#">Link</a>
                                    </li>
                                    <li class="dropdown">
                                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown
                                            <span class="caret"></span>
                                        </a>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a href="#">Action</a>
                                            </li>
                                            <li>
                                                <a href="#">Another action</a>
                                            </li>
                                            <li>
                                                <a href="#">Something else here</a>
                                            </li>
                                            <li role="separator" class="divider"></li>
                                            <li>
                                                <a href="#">Separated link</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </div>
                            <!-- /.navbar-collapse -->
                        </div>
                        <!-- /.container-fluid -->
                    </nav>
                </div>    <div class="col-md-1">
          <div style="background-color: #f0f0f0; margin-left: -30px; padding-left: 10px; position: fixed">
            <img src="https://cdn4.iconfinder.com/data/icons/dragon/512/User.png" alt="" class="" style="width:100px;  margin-left: 10px ">
          </div>
        </div>
      </div>
      <!--/.row-->
      <div style="height: 100vh;"></div>
    </div>
    <!--/.container-fluid-->
        2
  •  1
  •   fnostro    6 年前

    使用bootstrat 3 media styling

    在这个片段中,我只使用了1个嵌入式BS Nav,并添加了一个边框颜色来描绘媒体对象

    此外,引导导航响应迅速,因此当您运行代码段切换到展开视图时

    .media {
      border: 1px solid gray;
    }
    
    .media, .media-body {
      overflow: visible !important;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <div class="row">
      <div class="col-sm-offset-2 col-sm-8">
        <div class="media">
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <div>
              <nav class="navbar navbar-default">
                <div class="container-fluid">
                  <!-- Brand and toggle get grouped for better mobile display -->
                  <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
                    <a class="navbar-brand" href="#">Brand</a>
                  </div>
    
                  <!-- Collect the nav links, forms, and other content for toggling -->
                  <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                      <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                      <li><a href="#">Link</a></li>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                          <li><a href="#">Action</a></li>
                          <li><a href="#">Another action</a></li>
                          <li><a href="#">Something else here</a></li>
                          <li role="separator" class="divider"></li>
                          <li><a href="#">Separated link</a></li>
                          <li role="separator" class="divider"></li>
                          <li><a href="#">One more separated link</a></li>
                        </ul>
                      </li>
                    </ul>
                  </div>
                  <!-- /.navbar-collapse -->
                </div>
                <!-- /.container-fluid -->
              </nav>
            </div>
          </div>
          <div class="media-right">
            <a href="#">
              <img class="media-object" src="http://via.placeholder.com/80x80" alt="Portrait">
            </a>
          </div>
        </div>
        <div class="media">
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <nav>Nav</nav>
          </div>
          <div class="media-right">
            <a href="#">
              <img class="media-object" src="http://via.placeholder.com/80x80" alt="Portrait">
            </a>
          </div>
        </div>
        <div class="media">
          <div class="media-body">
            <h4 class="media-heading">Media heading</h4>
            <nav>Nav</nav>
          </div>
          <div class="media-right">
            <a href="#">
              <img class="media-object" src="http://via.placeholder.com/80x80" alt="Portrait">
            </a>
          </div>
        </div>
      </div>
    </div>