简体   繁体   中英

how to change the line color in the NavBar toggle button in react-bootstrap?

I would like to change the line color of the toggle button. i have tried to change the inline style of the Navbar.Toggle but it didnt work. Does someone have an idea?

在此处输入图像描述

Try changing the variant to dark so that the hamburger will display as light to contrast with the "dark" variant of the navbar.

<Navbar bg="transparent" expand="lg" variant="dark">

I just struggled with this for about an hour. Trying to change the stroke value in my sass to override the bootstrap default wasn't working for me, nor was any other deeper specificity rule that I tried.

What worked: Use a different background image and set it to.important, For example, I used the bootstrap "list" icon svg(downloaded from their site to an asset folder): which I set as the background for the same class that was being generated by bootstrap in the DOM:

.navbar-light .navbar-toggler-icon {
    background-image: url("../assets/list.svg") !important;
}

Then, in the actual SVG file (click the file in your code editor to edit), change the "fill" or "stroke" attributes to whatever color you like. Easy peasy:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="white" class="bi bi-list" viewBox="0 0 16 16">
  <path fill-rule="evenodd" d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5z"/>
</svg>

Try the adding a class to the button (or just override the current class of the hamburger button) and do the following:

.navbar-hamburger {
    background-image: url("data:image/svg+xml,<svg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'><path stroke='rgba(255,255,255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/></svg>");
}

And replace the stroke color. This was tested on plain bootstrap 4, I hope it works!

If you want background is dark, but the hamburger is light, try this

<Navbar bg="dark" expand="lg" variant="dark"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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