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.

编辑:也许我的措辞不是最好的...第一块代码已经可以工作了...我需要的是没有

包装器,如果那可能的话。浮动技巧?伪元素技巧?一定有办法。

更多相关文章

  1. 两个并列的div,一个确定宽度一个自动调整
  2. 如何让我的固定宽度移动网站始终显示“完全放大”?
  3. 从PHP数组创建HTML列表
  4. CSS3列 - 添加第二个元素后的额外宽度
  5. 如何使用“left:100%”CSS规则保留DIV宽度
  6. 使三个标签填充容器的宽度
  7. PHP选择具有特定宽度的图像并构建网格
  8. 上传文件时通过AJAX更新列表
  9. 如何用PHP和MYSQL在逗号分隔的列表中找到最流行的10个值

随机推荐

  1. Android webkit image的加载过程解析(二)
  2. Android官方技术文档翻译——Gradle 插件
  3. 获取Android的Java源代码并在Eclipse中关
  4. 当Google忙着忽悠Android的时候,各位别忘
  5. Android 中文API合集 chm版,电子书籍下载
  6. Android 中文 API――android.widget合集
  7. android 自定义组件 :对VelocityTracker的
  8. Android(安卓)SQLite使用详解和多线程并
  9. android基础入门(二)――创建android工程
  10. 2010-11-4