Css 对中问题<;ul>;在<;部门>;

Css 对中问题<;ul>;在<;部门>;,css,Css,我查阅了如何将无序列表居中,并找到了许多解决方案。但由于某种原因,我无法让它工作。我做错了什么 HTML: 编辑:屏幕截图-我想你要做的是将列表居中。 首先将您的ul作为显示器:块; 第二,删除你的浮动在li上,让他们显示:内联块 正如您在库中设置的“文本对齐:居中”。所有内联块元素都将居中,并且始终将内联块上的垂直对齐作为默认设置,我认为设置为基线 HTML <section id="gallery"> <ul> <li style="backgroun

我查阅了如何将无序列表居中,并找到了许多解决方案。但由于某种原因,我无法让它工作。我做错了什么

HTML:


编辑:屏幕截图-

我想你要做的是将列表居中。

首先将您的ul作为显示器:块; 第二,删除你的浮动在li上,让他们显示:内联块

正如您在库中设置的“文本对齐:居中”。所有内联块元素都将居中,并且始终将内联块上的垂直对齐作为默认设置,我认为设置为基线

HTML

<section id="gallery">
<ul>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
</ul>


如果您有任何问题,请告诉我。

您想实现什么?@VincentBeltman我想将无序列表放在父部分的中心。您必须将宽度设置为
ul
或从
li
中删除边距:是的,这解决了问题。但我不知道为什么它以前不起作用。这似乎对其他人都有效。不管怎样,谢谢。太好了。祝你好运,伙计。
#gallery {
    text-align: center;
}

#gallery ul{
    display: inline-block;
    padding: 0;
    list-style: none;
    overflow: hidden;
}

#gallery ul li {
    display: block;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -khtml-border-radius: 5px;
    width: 250px;
    height: 250px;
    margin: 2.5%;
    float: left;
}
<section id="gallery">
<ul>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
    <li style="background-image: url('.....');"></li>
</ul>
#gallery {
text-align: center;
width:100%;

    background:blue;
}
#gallery ul{
    display:block;
    padding: 0;
    list-style: none;
    overflow: hidden;
}

#gallery ul li {
    display: inline-block;
    vertical-align: top;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -khtml-border-radius: 5px;
    width: 50px;
    height: 50px;
    margin: 2.5%;
}

#gallery ul li {
    background-color:red;
}