Solution 1 :

.nav-bar {
  width: 100%;
  height: 10%;
  background-color : red;
}
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <title></title>
  </head>
  <body>
    <nav class="nav-bar">
      <img src="tesla_logo_PNG16.png" alt="logo" class="logo">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Log out</a></li>
      </ul>
    </nav>
  </body>
</html>

Color works only on text

Problem :

I have this really simple code. I am creating a navbar, in the CSS code when I try to style the navbar using the keyword “nav” that seems to work, but if I create a class suppose class=”nav-bar” and try to access it using .nav-bar in the CSS code and format it from there, nothing seems to happen.

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <title></title>
  </head>
  <body>
    <nav class="nav-bar">
      <img src="tesla_logo_PNG16.png" alt="logo" class="logo">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Log out</a></li>
      </ul>
    </nav>
  </body>
</html>

Here is the CSS that doesn’t work

.nav-bar {
  width: 100%;
  height: 10%;
  color: red;
}

Here is the CSS that works

nav {
  width: 100%;
  height: 10%;
  color: red;
}

Comments

Comment posted by Krzysztof Antosik

it is good practice to use the underscore in classes instead of a dash

Comment posted by Aniket Vishwakarma

Oh I am sorry, that was a typo on my part, while doing the actual code I did write .nav-bar both as class name and in the CSS code, but it didn’t change anything, that was the main problem I am facing. I have edited the question. I did check that link, and it seems the color only changes for the bullets,which is not what I was aiming for. And using background-color doesn’t change anything.

Comment posted by Bardales

what do you need?

Comment posted by Aniket Vishwakarma

I am a little confused about these bullets too, I don’t have them in my original code and they don’t show up when I open the original HTML document on chrome.

Comment posted by Aniket Vishwakarma

I just wanted to access the navbar via the class and change the background color

Comment posted by Bardales

You need the nav background color red?

By