How would I go about modifying the CSS to change the color of the navbar in Twitter Bootstrap?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- How to add a “active” class to a carousel first el
- Add animation to jQuery function Interval
- jQuery hover to slide?
Just add an id to the html navbar, such as:
With this id you can style the navbar color, but also the links and dropdowns
Examples applied to different types of navbars
Black
Yellow
Darkblue
Red (Cherry)
Darkgreen
Here is the CSS
It can be done directly by using style=" " attribute to whichever html tag you want to override it for eg.
this overrides bootstrap's default CSS.
There is no need to define a complete set of styling or CSS separately.
It took me a while, but I discovered that including the following was what made it possible to change the navbar color:
Updated 2018 for Bootstrap 4
Changing the Navbar color is different (and a little easier) in Bootstrap 4. You can create a custom navbar class, and then reference it to change the navbar without impacting other Bootstrap navs..
Bootstrap 4.0
The CSS required to change the Navbar is much less in Bootstrap 4...
Bootstrap 4 Custom Navbar Demo
Changing the active/hover link background color also works with the same CSS, but you must adjust the padding if you want the bg color to fill the full height of the link...
py-0
to remove vertical padding from the entire navbar...<nav class="navbar navbar-expand-sm navbar-custom py-0">..</nav>
Bootstrap 4 Change Link and Background Color Demo
Also see: Bootstrap 4 Change Hamburger Toggler Color
Bootstrap 3
Custom Navbar Demo on Bootply
If the Navbar has dropdowns, add the following to change dropdown color(s):
Demo with Dropdown
Using Less
You could also consider to compile your own version. Try http://getbootstrap.com/customize/ (which has a apart section for the Navbars settings (Default navbar and Inverted Navbar)) or download your own copy from https://github.com/twbs/bootstrap.
You will find the navbar settings in
variables.less
.navbar.less
is used to compile the navbar (depends onvariables.less
andmixins.less
).Copy the 'navbar-default section' and fill in your own color settings. Changing the variables in
variables.less
will be the easiest way (changing the default or inverse navbar won't be a problem because you have one navbar per page only).You won't change all settings in most cases:
You could also try http://twitterbootstrap3navbars.w3masters.nl/. This tool generates CSS code for your custom navbar. Optionally, you could also add gradient colors and borders to the navbar.
If it's only about changing the color of the Navbar my suggestion would be to use: Bootstrap Magic. You can change the values for different properties of the Navbar and see a preview. Download the result as a custom CSS style sheet or as a LESS variables file. You can change values with input fields and color pickers. Y