英文:
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%;
}
您可以更改具有类名words
的ul元素的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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论