Can I use CSS to add a bullet point to any element?

前端 未结 9 2159
名媛妹妹
名媛妹妹 2020-12-13 23:54

Pretty simple question, but I am not sure if it is possible. I want to add an image to act as a bullet in all

elements. I know I can achieve this b

9条回答
  •  青春惊慌失措
    2020-12-14 00:50

    While you can use a :before pseudo-selector to add a "-" or "•" character in front of your element, it doesn't really make your element behave like a bullet point. Your element may look like a bullet point, but that's just a dirty hack, really, and should be avoided!

    To make your element both (1) look like a bullet point and (2) behave like a bullet point, you should set the display, list-style-type and list-style-position attributes of that element.


    EXAMPLE CODE

    h1 {
        display: list-item;          /* This has to be "list-item"                                               */
        list-style-type: disc;       /* See https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type     */
        list-style-position: inside; /* See https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-position */
    }

    My H1 text here


    THE FIDDLE

    http://jsfiddle.net/L15a53cb/

提交回复
热议问题