Why does the list style disappear when display: block is added to a list item in a list (
    or
      )?

后端 未结 5 435
执笔经年
执笔经年 2020-12-05 13:45

This seems to valid for display: inline; and display: inline-block; too.

This is what I mean:

ul li {
  display: block;
  /         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 14:25

    Solution for ul

    ul {
        list-style: none;
        display: block;
        padding: 0;
    }
    
    ul li::before {
      content: "• ";
    }
    
    
    • list item1
    • list item3
    • list item3

    Solution for ol using counter-increment

    ol {
        list-style: none;
        display: block;
        padding: 0;
        counter-reset: my-counter;
    }
    
    ol li {
      counter-increment: my-counter;
    }
    
    ol li::before {
      content: counter(my-counter) ". ";
    }
    
    
    1. list item1
    2. list item3
    3. list item3

提交回复
热议问题