【问题标题】:How make a cross-browser custom list-style markers?如何制作跨浏览器的自定义列表样式标记?
【发布时间】:2011-11-14 09:33:29
【问题描述】:

我需要制作一个自定义列表样式的标记。现在是通过在li前添加元素来完成的,但是存在一个问题。其余行应与标记的文本对齐,例如普通标记列表,但它们不会。

li p::before {
    content: "* ";
}

如何为第二行、第三行等进行填充,并使其跨浏览器? (IE8+、FF3+、Opera 11+ 和 Crome)

【问题讨论】:

  • 你不能使用图像作为列表样式吗?我认为它会更简单。
  • 很遗憾,这是不可能的。

标签: css


【解决方案1】:
li p:before { /* thanks Michael */
    content: "* ";
    float:left;
}
li p {
    overflow:auto;
}

也许这会奏效。我可以知道你为什么不能使用图片(单纯的好奇)?

编辑:我错了,:before 在 content 之前插入伪元素,所以

<div id="wrap">

    <ul>

        <li><p>Get order of list items in a jQuery Sortable list after resort ... The trick is I would like to capture the order of the items immediately ... And I'm aware that it's also possible to assign a call-back function that fires when sorting st</p></li>
    </ul>
</div>

#wrap
{
    position: absolute;
    top: 100px;
    left: 100px;
}

li
{
    list-style-type: none;
}

li p
{
    overflow:auto;
}

li:before {
    content: "* ";
    float:left;
}

会起作用的。

【讨论】:

  • 如果您使用p:before 而不是p::before 它也可以在IE8 中使用。新的浏览器也支持CSS2方式。
  • 对的,我不注意就粘贴了-_-
  • 完美的工作和令人难以置信的 tnx!其他人,可以在这里查看jsfiddle.net/mbarinov/S8cvJ
  • 不客气!然而真正的跨浏览器自定义标记应该是图像 =P
【解决方案2】:

您可以将 p 和 li 设置为浮动:left; (example 1)

li
{
    list-style-type: none;
    display: inline-block;
}

li p
{
    display: inline-block;
}

或将显示设置为 inline-block (example 2)

li
{
    list-style-type: none;
    display: inline-block;
}

li p
{
    display: inline-block;
}

【讨论】:

  • 当然不行,即使没有自定义标记,一个带有多行文本的&lt;li&gt; 也不会生成多个项目符号。您需要将每一行拆分为单独的 li/p 对。
猜你喜欢
  • 2011-09-28
  • 1970-01-01
  • 2017-02-05
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多