Is there a way to only change the color of marker (dots) when using display list-item?

  Kiến thức lập trình

I am using a display:list-item for the div pseudo-element::before. We can style the shape of the marker either disc or square…

.calendar{
    display: block;
    position: relative;
    width: 100px;
    aspect-ratio: 1;
    background-color: green;
}

.calendar::before{
    content:"Reserved";
    display: list-item;
    position: absolute;
    bottom: 0;
    right: -100%;
    color: black;
    list-style-type: disc;      /* or list-style-type: square; */
}
<div class="calendar"></div>

Can we change the color of marker without changing the content color (without using list-style-image)?

0

Not as you have it, pseudo-elements can’t have pseudo-elements (like ::marker) as would be required here.

Swap out the pseudo-element for a span instead.

.calendar{
    display: block;
    position: relative;
    width: 100px;
    aspect-ratio: 1;
    background-color: green;
}

.status {
    display:list-item;
    position: absolute;
    bottom: 0;
    right: -100%;
    color: black;
    list-style-type: disc;      /* or list-style-type: square; */
}

::marker {
  color: red;
}
<div class="calendar">
  <span class="status">Reserved</span>
</div>

2

You can use an image but without introducing a real image. A gradient can do the job:

.calendar{
    display: block;
    position: relative;
    width: 100px;
    aspect-ratio: 1;
    background-color: green;
}

.calendar::before{
    content:"Reserved";
    display: list-item;
    position: absolute;
    bottom: 0;
    right: -100%;
    color: black;
    list-style-image: radial-gradient(circle closest-side,red 90%,#0000);
    /* for a square
    list-style-image: linear-gradient(red 0 0);
    */
}
<div class="calendar"></div>

1

LEAVE A COMMENT