如何使用背景图像制作固定导航栏?

时间:2017-07-18 14:26:14

标签: html5 twitter-bootstrap css3

强文* desired result, how can I add the design marked with the red circle...[![this is my current result] 2 *

*

**我已经尝试过这些html和CSS代码来获得所需的结果。我还应该添加或减少我的HTML或CSS? 建议请。

body {
    margin: 0;
    padding: 0;
    font-size: 14px;
    color: black;
    background-color: #f3f1f2;
}
.firstPart {
    background: url('bannerFirst.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    min-height: 100%;
    padding-top: 0px;
    padding-bottom: 957px;
}
.navbar-default {
    background: none;
}
.navbar-default .navbar-collapse {
    border-color: #e7e7e7;
    background-color: transparent;
}
.backgroundImage {
    width: device-width;
}
.nav navbar-nav {
    font-size: 14px;
    font-family: "Alegreya";
    color: rgb(255, 255, 255);
    text-transform: uppercase;
    line-height: 1.714;
    position: absolute;
    left: 413.844px;
    top: 23.002px;
    z-index: 275;
    display: inline-block;
    padding-right: 44px;
    padding-top: 4px;
}
.headerArea {
    color: white;
    font-size: 30px;
    margin-top: -360px;
    margin-left: 375px;
}

这是css:

{{1}}

2 个答案:

答案 0 :(得分:0)

position:fixed;
top:0;
left:0;

看看this

如果这不是那个,你能不能在jsfiddle中给出你的代码:) 感谢

答案 1 :(得分:0)

您可以使用解决方案https://jsfiddle.net/ctoL942n/

body { 
  margin: 0; 
  padding: 0; 
  font-size: 14px; 
  color: black; 
  background-color: #f3f1f2;
} 

.firstPart{ 
  background: url('http://www.butcherblock.com/wp-content/uploads/2012/06/Pleasanton0031.jpg'); 
  background-repeat: no-repeat; 
  background-size: cover;
  min-height:100%; 
  padding-top: 0px; 
  padding-bottom: 957px; 
  background-position:0px 50px;
} 
.navbar-default { background: none; } .navbar-default .navbar-collapse{ border-color: #e7e7e7; background-color: transparent; }
.backgroundImage{ width: device-width; } .nav navbar-nav. Welcome_____~_____Menu_____~_____reservations__ { font-size: 14px; font-family: "Alegreya"; color: rgb(255, 255, 255); text-transform: uppercase; line-height: 1.714; position: absolute; left: 413.844px; top: 23.002px; z-index: 275; display: inline-block; padding-right: 44px; padding-top: 4px; } .headerArea{ color: white; font-size: 30px; margin-top: -360px; margin-left: 375px; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="firstPart">
          <nav class="navbar navbar-default navbar-fixed-top">
              <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="#">Gustoso</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="#">Welcome<span class="sr-only">(current)</span></a></li>
                    <li><a href="#">Menu</a></li>
                    <li><a href="#">Reservation</a></li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><i class="fa fa-twitter"></i></li>
                <li><i class="fa fa-twitter"></i></li>
                <li><i class="fa fa-twitter"></i></li>
            </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
       </nav>

    </div> <!--.firstPart-->
    <section class="headerArea">
        <h1>Pastry With Love</h1>

    </section><!--.headerArea-->

使用 background-position:0px 50px; 从特定位置启动背景图片。