thiebo
thiebo

Reputation: 1435

how to add a li with the before selector css

I'm trying to add a li before the li in a list doing this:

ul.ssmenu:first-child::before{
    li{
        position: relative;
        height: 10px;
    }
}

This doesn't seem to be the right solution.

Upvotes: 0

Views: 2915

Answers (2)

grinmax
grinmax

Reputation: 1855

Try this

ul.ssmenu{
    li:first-child::before{
        position: relative;
        height: 10px;
    }
}

Upvotes: 0

Asons
Asons

Reputation: 87231

You can't add an element like that using CSS only, the ::before is an element though, a pseudo element, and you could do like this..., and if you need more li, you'll need to use a script

ul li,
ul::before,
ul::after {
  position: relative;
  height: 20px;
}
ul::before {
  content: 'This li were added with CSS pseudo ::before';
  display: list-item;
}
ul::after {
  content: 'This li were added with CSS pseudo ::after';
  display: list-item;
}
<ul>
  <li>This "li" exist in markup</li>
</ul>

Upvotes: 1

Related Questions