如何集中无序列表?
I need to center an unordered list of unknown width, while still keeping the list-items left aligned.
我需要将无序宽度的无序列表居中,同时仍保持列表项左对齐。
Achieve the same result as this:
获得与此相同的结果:
HTML
HTML
<div>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</div>
CSS
CSS
div { text-align: center; }
ul { display: inline-block; text-align: left; }
Except my <ul>
doesn't have a parent div. ul { margin: 0 auto; }
doesn't work because I don't have a fixed width. ul { text-align: center; }
doesn't work because the list-items won't be left aligned anymore. So how can I center this <ul>
while keeping the <li>
s left aligned (without having a parent div wrapper)?
除了我的
-
没有父div。 ul {margin:0 auto; }不起作用,因为我没有固定的宽度。 ul {text-align:center; }不起作用,因为列表项不再左对齐。那么如何在保持
- 左对齐(没有父div包装器)的同时将这个
-
居中?
- 左对齐(没有父div包装器)的同时将这个居中?
<ul>
<li></li>
<li></li>
<li></li>
</ul>
EDIT: Perhaps my wording wasn't the best... The first block of code already works... what i need is to do it without the <div>
wrapper, if that's possible of course. Float tricks? Pseudo element tricks? There must be a way.
编辑:也许我的措辞不是最好的...第一块代码已经可以工作了...我需要的是没有
包装器,如果那可能的话。浮动技巧?伪元素技巧?一定有办法。更多相关文章
- 两个并列的div,一个确定宽度一个自动调整
- 如何让我的固定宽度移动网站始终显示“完全放大”?
- 从PHP数组创建HTML列表
- CSS3列 - 添加第二个元素后的额外宽度
- 如何使用“left:100%”CSS规则保留DIV宽度
- 使三个标签填充容器的宽度
- PHP选择具有特定宽度的图像并构建网格
- 上传文件时通过AJAX更新列表
- 如何用PHP和MYSQL在逗号分隔的列表中找到最流行的10个值