0

I have tried so many things and am still a beginner to HTML and CSS, was wondering if anyone knows why the list is not centering in the navbar.

<!DOCTYPE html>
<html lang="en">
<head>
  <link href="https://fonts.googleapis.com/css2?family=Merriweather+Sans&display=swap" rel="stylesheet">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  
  <div class="bar">
    <ul class="words">
      <li class ="Keyboards">Keyboards</li>
      <li class ="Accessories">Accessories</li>
      <li class ="In_Stock">In Stock</li>
      <li class ="Group_Buy">Group Buy</li>
      <li class ="Support">Support</li>    
    </ul>
  </div>
  
</head>
<body>
  
</body>
</html>
*{
  margin: 0;
  padding: 0;
}

body{
  background-color: rgb(41, 41, 41);
  font-family: 'Merriweather Sans', sans-serif;
  font-style: bold;

}

.bar{
  background-color: rgb(69, 69, 69);
  height: 75px;
}

li{  
  display: inline-block;
  padding-left: 10px;
  padding-right: 10px;
  font-size: 25px;
  margin: auto;
}

I have tried lots of margins and display flex. Still nothing that works

Brandon
  • 21
  • 5
  • I think you need "margin: auto" on the ul, not the li. The ul (class="words") is the child, not the li. – Ryan May 31 '23 at 23:56

1 Answers1

1

try this:

.bar{
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgb(69, 69, 69);
  height: 75px;
}

.words{
  width: 30%;
}

you can change the width of the ul element with the class words.