Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使固定导航栏水平居中?_Html_Css_Html Lists - Fatal编程技术网

Html 如何使固定导航栏水平居中?

Html 如何使固定导航栏水平居中?,html,css,html-lists,Html,Css,Html Lists,我环顾四周,无法找到如何水平居中我的固定导航栏 如果可以的话,你能告诉我怎么做并解释原因吗 谢谢 #导航{ 列表样式:无; 位置:固定; 利润上限:-10px; 宽度:100%; 字体系列:产品Sans; 字号:0; } #李海军{ 宽度:200px; 高度:50px; 显示:内联块; 文本对齐:居中; 垫面:5px; 背景色:白色; 字体大小:30px; } 堆叠 结束 流动 您必须将ul内的li项目居中对齐 因此CSS将是 <style> #nav{ list-styl

我环顾四周,无法找到如何水平居中我的固定导航栏

如果可以的话,你能告诉我怎么做并解释原因吗

谢谢

#导航{
列表样式:无;
位置:固定;
利润上限:-10px;
宽度:100%;
字体系列:产品Sans;
字号:0;
}
#李海军{
宽度:200px;
高度:50px;
显示:内联块;
文本对齐:居中;
垫面:5px;
背景色:白色;
字体大小:30px;
}
  • 堆叠
  • 结束
  • 流动

您必须将ul内的li项目居中对齐

因此CSS将是

<style>

#nav{
  list-style: none;
  position: fixed;
  margin-top: -10px;
  width: 100%;
  font-family: Product Sans;
  font-size: 0;
  text-align:center;
  padding-left:0px;
}
#nav li{
  width: 200px;
  height: 50px;
  display: inline-block;
  text-align: center;
  padding-top: 5px;
  background-color: white;
  font-size: 30px;
}


</style>

#导航{
列表样式:无;
位置:固定;
利润上限:-10px;
宽度:100%;
字体系列:产品Sans;
字号:0;
文本对齐:居中;
左侧填充:0px;
}
#李海军{
宽度:200px;
高度:50px;
显示:内联块;
文本对齐:居中;
垫面:5px;
背景色:白色;
字体大小:30px;
}

并保持html不变

只需添加
文本对齐:居中#nav,如下所示:

<style>
 #nav{
  list-style: none;
  position: fixed;
  margin-top: -10px;
  width: 100%;
  font-family: Product Sans;
  font-size: 0;
  text-align: center; /* <--- */
}
</style>

#导航{
列表样式:无;
位置:固定;
利润上限:-10px;
宽度:100%;
字体系列:产品Sans;
字号:0;
文本对齐:居中/*