如何制作具有彩色效果的粘页眉

时间:2018-07-11 11:12:30

标签: javascript jquery css html5

我想制作一个粘性标头,类似于本网站的fcinq.com 但是我对 navbar 和菜单颜色样式感到有些困惑。 我将容器放在标头中并将其分为两部分,但无法像fcinq.com

那样制作粘性标头

那么我该如何像fcinq.com一样制作标题? 网站链接:https://www.fcinq.com/

<nav class="navbar navbar-inverse" role="navigation" style="">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="col-md-8" style="margin-bottom: 200px;">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <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="#about">Jhon Budy</a>
      </div>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="col-md-4" style="background: blue;/*! margin-bottom: 68px; */">
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav navbar-right">

          <li class="current" style="margin-top: 102px;margin-bottom: 60px;"><a href="#about">About</a>
            <a href="#work">Work</a>
            <a href="#contact">Contact</a></li>
        </ul>


      </div>
      <!-- /.navbar-collapse -->
    </div>
  </div>
  <!-- /.container-fluid -->
</nav>

3 个答案:

答案 0 :(得分:1)

由于您似乎正在使用引导程序

https://getbootstrap.com/docs/3.3/components/#navbar-fixed-top

将您的导航代码更改为

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="">

答案 1 :(得分:0)

您的问题不是很清楚,但是据我所知,您可以直接将以下CSS包括在内,并根据需要修改内容。在您的<header></header>中加入index.html

header {
position: fixed;
z-index: 1111;
left: 0px;
right: 0px;
top: 28px;
height: 28px;
line-height: 28px;
text-align: center;
color: #fff;
background: #24397a;
box-sizing: border-box;
padding: 0 6px;
margin: 0px;
font-size: 20px;
text-transform: capitalize;
display: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

您还可以在标头tag中包含其他元素,例如锚标签,徽标等。

希望这会有所帮助!

答案 2 :(得分:0)

这是我黏贴头的小提琴 https://jsfiddle.net/Nethravathi/y7x9vost/1/

$(function(){
    $('.navbar').affix({
      offset: {
        /* Affix the navbar after scroll below header */
        top: $("header").outerHeight(true)}
    });
});
@import url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css);

/* To mantain the navbar at the bottom*/
header {
  width: 100%;
  min-height:calc(100vh - 52px);
}


/* To mantain the navbar at the top once it is affixed */
.affix {
    top: 0;
    width: 100%;
  }

/* Padding for a smoth affix */
.affix + .container-fluid {
  padding-top: 72px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header class='container-fluid'>
  <h1>Title</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac neque et sem molestie scelerisque.<br/>In felis sem, pharetra ornare mi et, mattis rhoncus est.<br/>Fusce id nulla et enim molestie fermentum sed ullamcorper nibh. </p>
</header>

<nav class='navbar navbar-default'>
  <div class='container'>
    <div class='navbar-header'>
      <button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>
        <span class='sr-only'>Toggle Navigation</span>
        <span class='icon-bar'></span>
        <span class='icon-bar'></span>
        <span class='icon-bar'></span>
      </button>
      <a href='#' class='navbar-brand'> Title</a>
    </div>

    <div class='collapse navbar-collapse'>
      <ul class='nav navbar-nav navbar-right'>
        <li><a href=''>Link</a></li>
        <li><a href=''>Link</a></li>
        <li><a href=''>Link</a></li>
        <li><a href=''>Link</a></li>
      </ul>
    </div>
  </div>
</nav>

<div class='container-fluid'>
  <h1>Title</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac neque et sem molestie scelerisque.<br/>In felis sem, pharetra ornare mi et, mattis rhoncus est.<br/>Fusce id nulla et enim molestie fermentum sed ullamcorper nibh. </p>
  <h1>Title</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac neque et sem molestie scelerisque.<br/>In felis sem, pharetra ornare mi et, mattis rhoncus est.<br/>Fusce id nulla et enim molestie fermentum sed ullamcorper nibh. </p>
  <h1>Title</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac neque et sem molestie scelerisque.<br/>In felis sem, pharetra ornare mi et, mattis rhoncus est.<br/>Fusce id nulla et enim molestie fermentum sed ullamcorper nibh. </p>
  <h1>Title</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ac neque et sem molestie scelerisque.<br/>In felis sem, pharetra ornare mi et, mattis rhoncus est.<br/>Fusce id nulla et enim molestie fermentum sed ullamcorper nibh. </p>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>