列表未居中。

huangapple go评论64阅读模式
英文:

List is not centering

问题

我尝试了很多不同的边距和flex布局,但仍然没有找到有效的方法使列表在导航栏中居中显示。

英文:

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

答案1

得分: 1

尝试这个:

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

.words{
  width: 30%;
}

您可以更改具有类名wordsul元素的width

英文:

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.

huangapple
  • 本文由 发表于 2023年6月1日 07:53:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定