繁体   English   中英

我如何居中 <ul> 元件?

[英]How do I center a <ul> element?

我对这里的一些代码有一个快速的问题:

h1 {
    font - size: 65 px;
    color: orange;
    text - align: center;
    height: 20 px;
    font: Times;
}

h2 {
    text - align: center;
    font: Times;
}

ul {
    width: 1230 px;
    list - style - type: none;
    overflow: hidden;
    background - color: #C2C6DD;
    justify - content: center;
}

h1h2是网页的标题,居中。 但是,ul(导航栏)没有居中,我尝试了许多不同的方法,例如align-items,text-align,它始终位于页面的左侧。 有人可以帮忙吗?

在此处输入图片说明

您尝试以下代码:

 ul{
  list-style-type:none;
  display:flex;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  background-color: #C2C6DD;
  text-align: center;
}

尝试添加margin: 0 auto; 对ul:

ul {
    width: 1230px;
    list-style-type: none;
    overflow: hidden;
    background-color: #C2C6DD;
    margin: 0 auto;
}

试试看:

ul {
    width: 1230 px;
    list - style - type: none;
    overflow: hidden;
    background - color: #C2C6DD;
    justify - content: center;
    margin: 0 auto;
    text-align: center;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM