通过导航

时间:2018-05-20 03:12:19

标签: html css twitter-bootstrap-3

我正在尝试将此站点复制为bootstrap学习课程的一部分。 (https://trickyicky84.000webhostapp.com/)。 HTML有导航后跟一个section元素(带有类简介),并且有一个背景图像应用于section元素。

您可以看到导航在View Port< 768中的背景为暗,但变为透明> 768并且应用了背景图像。介绍部分似乎在导航中显示出来。我无法确定哪个代码使导航透明,更重要的是如何将背景图像应用于剖面,应用于nav元素。

我假设是这样的:

@media(min-width:767px) {
    .navbar {
        padding: 20px 0;
        border-bottom: none;
        letter-spacing: 1px;
        background: transparent;
        -webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
        -moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
        transition: background .5s ease-in-out,padding .5s ease-in-out;
    }

我在我自己的版本中尝试了类似的代码(制作背景:导航栏是透明的)但它似乎采用了背景:来自Bootstrap的0 0样式给它一个灰色的颜色。我还没有研究过CSS转换,我不确定是否使用原始站点中的转换来完成。我的网站位于https://trickyicky83.000webhostapp.com/

正在运行的版本的完整CSS:

@import "vendors/bootstrap/bootstrap.less";
@import "vendors/font-awesome/font-awesome.less";

@primary: #26a5d3;
@dark: #333333;
@light: #f4f4f4;

html{
    width:100%;
    height:100%;
}

body{
    width:100%;
    height:100%;
    font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
    color:@dark;
    background-color:@light;
}

// Typography

h1, h2, h3, h4, h5, h6{
    margin: 0 0 35px;
    text-transform:uppercase;
    font-family: "Montserrat","Helvetica Neue",Helvetica,Arial,sans-serif;
    letter-spacing:1px;
}

p{
    margin: 0 0 25px;
    font-size:18px;
    line-height:1.6em;
}

a{
    color:@primary;

}

a:hover,a:focus{
    text-decoration:none;
    color: darken(@primary, 20%);
}


// Navigation

 .navbar {
    margin-bottom: 0;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    text-transform: uppercase;
    font-family: "Montserrat","Helvetica Neue",Helvetica,Arial,sans-serif;
    background-color: @dark;
}

.navbar-brand {
    font-weight: 700;
}

.navbar-brand:focus {
    outline: none;
}

.navbar-custom a {
    color: @light;
}

.navbar-custom .nav li a {
    -webkit-transition: background .3s ease-in-out;
    -moz-transition: background .3s ease-in-out;
    transition: background .3s ease-in-out;
}

.navbar-custom .nav li a:hover,
.navbar-custom .nav li a:focus,
.navbar-custom .nav li.active {
    outline: none;
    background-color: rgba(255,255,255,0.2);
}

.navbar-toggle {
    padding: 4px 6px;
    font-size: 16px;
    color: @light;
}

.navbar-toggle:focus,
.navbar-toggle:active {
    outline: none;
}

@media(min-width:767px) {
    .navbar {
        padding: 20px 0;
        border-bottom: none;
        letter-spacing: 1px;
        background: transparent;
        -webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
        -moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
        transition: background .5s ease-in-out,padding .5s ease-in-out;
    }

    .top-nav-collapse {
        padding: 0;
        background-color: @dark;
    }

    .navbar-custom.top-nav-collapse {
        border-bottom: 1px solid rgba(255,255,255,0.3);
    }
}


// Landing Page

.intro{
    display:table;
    width:100%;
    height:auto;
    padding:100px 0;
    text-align:center;
    color:@light;
    background: url(../img/intro-bg.jpg) no-repeat bottom center scroll;
    background-color:@dark;
    -webkit-background-size:cover;
    -moz-background-size:cover;
    -o-background-size:cover;
    background-size:cover;
}

.intro-body{
    display:table-cell;
    vertical-align:middle;
}

.brand-heading{
    font-size:40px;
}

.intro-text{
    font-size:18px;
}

@media(min-width:767px) {
    .intro{
        height:100%;
        padding:0;
    }

    .brand-heading{
        font-size:100px !important;
    }

    .intro-text{
        font-size:25px;
    }
}

这是我的版本无效:

@import "vendor/bootstrap/bootstrap.less";
@import "vendor/font-awesome/font-awesome.less";

@primary: #26a5d3;
@dark: #333333;
@light: #f4f4f4;

body {
    margin-top:50px;
    background-color: @light;
    color:@dark;
    font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
}

// typography 

h1,h2,h3,h4,h5,h6 {
    text-transform:uppercase;
    margin:0 0 30px;
    letter-spacing:1px;

}

p {
    margin: 0 0 25px;
    font-size:18px;
    line-height:1.6em;
}

// Navigation

 .navbar {
    margin-bottom: 0;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    text-transform: uppercase;
    font-family: "Montserrat","Helvetica Neue",Helvetica,Arial,sans-serif;
     background-color:@dark;   

}

.navbar .navbar-brand {
    font-weight:700;
    color:@light;
} 

.navbar .nav li a {
    color:@light;
}

.navbar .nav li a:hover {
    color:@light;
}
.navbar .nav li a {
    -webkit-transition: background .3s ease-in-out;
    -moz-transition: background .3s ease-in-out;
    transition: background .3s ease-in-out;
}
.navbar .nav li a:hover,
.navbar .nav li a:focus,
.navbar .nav li.active {
    outline: none;
    background-color: rgba(255,255,255,0);
}
@media(min-width:768px) {
    .navbar {
        padding:20px 0 ;
        letter-spacing:1px;
        background: transparent;
        -webkit-transition: background .5s ease-in-out,padding .5s ease-in-out;
        -moz-transition: background .5s ease-in-out,padding .5s ease-in-out;
        transition: background .5s ease-in-out,padding .5s ease-in-out;    
    }
}

//intro 

.intro {
    display:table;
    padding:100px 0;
    width:100%;
    color:@light;
    background: url(../img/intro-bg.jpg) no-repeat bottom center;
    background-color:@dark;
    -webkit-background-size:cover;
    -moz-background-size:cover;
    -o-background-size:cover;
    background-size:cover;
}
.intro-body {
    display:table-cell;
    vertical-align:middle;
}

.intro h1 {
    font-size:40px;
}

.intro p {
    font-size:18px;
} 

@media(min-width:767px) { 
    .intro h1 {
        font-size:100px !important;     
    }
    .intro p {
        font-size:25px;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试更新类似的CSS代码。另外,从margin-top: 50px

中删除body属性
.navbar {
    margin-bottom: 0;
    border-bottom: 1px solid rgba(255,255,255,.3);
    text-transform: uppercase;
    font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
    background-color: #333;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
}