htmlcsstwitter-bootstrap

Change font color inside nav


Hello I'm a newcomer and I want to change the color of the font inside the navbar but cant find any solution, here is the code:

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">testteee</a>
    </div>
    <ul class="nav navbar-nav navbar-right">
      <li class="active"><a href="#">About</a></li>
      <li><a href="#">Portofolio</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </div>
</nav>
<main>
  <header>
    <p>teste</p>
  </header>
</main>

CSS:

body {
  background-color: grey;
}
.navbar {
  background-color: purple;
  border: transparent;
  box-shadow: 0px 0px 0px 2px grey;
  margin: 0;
}
main {
  width: 60%;
  background-color: white;
  margin: 0 auto;
  box-shadow: 0.5px 0.5px 0.5px 0.5px grey;
}

Any additional tips would be great for my development :)


Solution

  • This might be what you need, but I'd suggest you to to change this from sass/scss variables. It might be a long way because you have to learn how to build bootstrap css files in a nodejs environment, this can help.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <style>
            body {
              background-color: grey;
            }
            .navbar-custom {
              background-color: purple;
              border: transparent;
              box-shadow: 0px 0px 0px 2px grey;
              margin: 0;
            }
            .navbar-custom .navbar-header a,
            .navbar-custom .navbar-header a:hover {
              color: #fff;
            }
            .navbar-custom ul.navbar-nav li a:hover {
              background-color: gray;
              color: #fff;
            }
            .navbar-custom ul.navbar-nav a {
              color: #fff;
            }
            .navbar-custom ul.navbar-nav a:hover {
              color: blue;
            }
    
            main {
              width: 60%;
              background-color: white;
              margin: 0 auto;
              box-shadow: 0.5px 0.5px 0.5px 0.5px grey;
            }
        </style>
    </head>
    <body>
    <nav class="navbar navbar-default navbar-custom">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">Logo</a>
        </div>
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#">About</a></li>
          <li><a href="#">Portofolio</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </div>
    </nav>
    <main>
      <p>main content</p>
    </main>
    </body>
    </html>

    Also, I think it's a bad practice and it's not scalable to use !important.

    You can read something about when to use important and perhaps some css specificity :)