简体   繁体   English

如何更改导航栏文本后面的背景颜色和高度?

[英]How can I change the colour and height of the background behind the navigation bar text?

I was wondering how I can change colour and height of the background behind the navigation bar text? 我想知道如何更改导航栏文本后面的背景颜色和高度? I'm aware I have to use CSS. 我知道我必须使用CSS。 However, I'm not sure of what class I have to pick from the html. 但是,我不确定我必须从html中选择哪个类。 Here is my codepen . 这是我的codepen

Furthermore, I have listed my HTML code of the navigation bar below. 此外,我在下面列出了导航栏的HTML代码。

<body>
        <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="#"><img src="http://placehold.it/60x60" alt="Your Brand Name"></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><a href="#">Home</a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">About Me <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>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Units <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>
                            <li><a href="#">Clients</a>
                            </li>
                            <li><a href="#contact-me">Contact Me</a>
                            </li>
                        </ul>
                      </div><!-- /.navbar-collapse -->
                    </div><!-- /.container-fluid -->
        </nav>

CSS code below. 下面的CSS代码。 (Could the issue be of the bootstrap method of the styling sheet?) (问题可能出在样式表的引导方法上吗?)

<style>
    body {
        margin: 0;
        padding: 0;
    }
    navbar-header {
        height: 15vh;
        background-color: #4D5061;
    }
    nav ul {
        list-style-type: none;
        text-align: center;
    }
    nav ul li {
        display: inline-block;
    }
    nav ul li a {
        display: inline-block;
        padding: 3.5vh 8px 4px;
        color: white;
        text-decoration: none;
        font-size: 14pt;
        font-family: 'Roboto', sans-serif;
    }
    nav ul li:after {
        content: '';
        position: absolute;
        right: 50%;
        bottom: 0;
        left: 50%;
        height: 3px;
        background-color: red;
        border-radius: 9px;
        transition:all .2s;
    }
    nav ul li:hover:after {
        right: 0;
        left: 0;
    }
    a:hover {
        color:red;
        text-decoration:none;
    }
    #logo {
        padding-top: 2vh;
        padding-left: 20px;
        float: left;
    }
    section {
        position: relative;
    }
    .section1 {
        height: 93vh;
        background-color: #FFFFFF;
        text-align: center;
    }
    .section2 {
        height: 93vh;
        background-color: #A59E8C;
        text-align: center;
        color: white;
    }
    .contact_section {
        height: 93vh;
        background-color: grey;
    }
    .logo {
        color: #000000;
        font-size: 200px;
    }
    .fa-angle-down {
        color: #4D5061;
        position: absolute;
        bottom: 0px;
    }
    footer {
        height: 10vh;
    }
</style>

Kind Regards, Liam. 亲切的问候,利亚姆。

.navbar.navbar-default will target it with your existing markup and with enough specificity to override bootstrap's default styling. .navbar.navbar-default将使用您现有的标记作为目标,并具有足够的特异性以覆盖bootstrap的默认样式。

.navbar.navbar-default {
  background: red;
  min-height: 200px;
}

您可以使用“ .navbar span”选择器,它应该应用于导航栏中的所有span标签。如果只想选择特定的span标签,则可以在我上面为类编写的选择器中更改“ span”您要修改的span标签的名称,让我知道它是否有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法更改导航栏的背景颜色 - Can't change background colour of navigation bar 如何覆盖导航栏的背景颜色使其与Jumbotron BG颜色相同? - How can I override my navigation bar background colour to be the same as jumbotron BG colour? 如何更改下拉菜单文本和导航栏下拉菜单背景颜色不透明度的文本位置? - How can I change the text position of drop down menu text & nav bar drop down menu background colour opacity? CSS:如何更改引导程序导航栏背景色 - CSS: How can I change bootstrap navigation bar background color 导航栏的背景颜色 - Background colour for Navigation bar 有没有一种方法可以在文本向上流动或向上滚动文本时更改 html5 中导航栏的背景? - Is there a way i can change the background of the navigation bar in html5 as the text flow up or as i scroll the text up? 如何更改背景色的不透明度? - How can I change the opacity of a background colour? h1“hello world”文本隐藏在导航栏后面我该如何解决这个问题 - h1 “hello world” text hiding behind of navigation bar how can i fix this 将鼠标悬停在导航栏中时,如何在文本后面填充背景? [HTML / CSS] - How can I fill in the background behind text when I hover over it in a nav bar? [HTML/CSS] 如何在此脚本中更改文本颜色? - How can I change the text colour in this script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM