简体   繁体   English

如何使引导导航栏的背景透明?

[英]How do you make the background of a bootstrap navbar transparent?

I'm having trouble making the background of the following navbar transparent.我无法使以下导航栏的背景透明。 I've tried making background-color: transparent;important.我试过制作背景颜色:透明;重要。 for.navbar but that doesn't seem to work either. for.navbar 但这似乎也不起作用。

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarnavdropdown" aria-controls="navbarnavdropdown" aria-expanded="false" aria-label="toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarnavdropdown">
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="index.html"><img src="assets/img/resultheap-logo.png" alt="" /></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="about.html">About</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="services.html">Services</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="blog/index.html">Blog</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="faq.html">FAQ</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="contact-form/index.html">Contact</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardropdownmenulink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    dropdown link
                </a>
                <div class="dropdown-menu" aria-labelledby="navbardropdownmenulink">
                    <a class="dropdown-item" href="#">action</a>
                    <a class="dropdown-item" href="#">another action</a>
                    <a class="dropdown-item" href="#">something else here</a>
                </div>
            </li>
        </ul>
    </div>
</nav>

remove the bg-light class from the nav element, or override it inline or id with important.从 nav 元素中删除 bg-light class,或者用重要的 inline 或 id 覆盖它。 But the cleanest way is to remove simply the class.但最干净的方法是简单地删除 class。 I think you could simply not override it because bootsstrap sets the color with the bg-light class also with.important.我认为你不能简单地覆盖它,因为 bootsstrap 使用 bg-light class 也使用.important 设置颜色。

I don't believe you may have mentioned it but have you tried the the 'opacity' css.我不相信您可能已经提到它,但您是否尝试过“不透明度”css。 You can do:你可以做:

opacity: 0; //Makes fully transparent
opacity: 0.5; //Half transparent
opacity 1; //No transparency

Hopefully this helps for the navbar.希望这对导航栏有所帮助。 Let me know if it doesn't, i'll try and help in any way possible.如果没有,请告诉我,我会尽一切可能提供帮助。

You can add a new css class as background-color: transparent;您可以添加一个新的 css class 作为 background-color: transparent; or you can change property of ".bg-light" class.或者您可以更改“.bg-light”class 的属性。

.bg-light {background-color:Transparent!important}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM