Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add padding to :before pseudo-element in css

Anyone know how to add padding between the :before pseudo-element and where the content actually starts?

<ul>
    <li><strong>Name Surname</strong></li>
    <li>+27.082.555.4155</li>
</ul>

I want only the first li to have a bullet point in it and only if it has a strong element in it.

I have gotten it right using:

.fr_contactInformation ul li strong:before
{
    content:url(/App_Themes/2011/images/hm_listImage.gif);
}

.fr_contactInformation ul li strong
{
    /*Here is where I am going wrong*/
    padding-left: 50px;
}

Thanks all!

like image 565
Sixfoot Studio Avatar asked Feb 24 '11 08:02

Sixfoot Studio


3 Answers

you can put padding in the before to make space between it and the element

.fr_contactInformation ul li strong:before
  {
      content:url(/App_Themes/2011/images/hm_listImage.gif);
      padding-left:50px;
   }
like image 193
generalhenry Avatar answered Nov 01 '22 18:11

generalhenry


If you want to control it by pixel, and assuming you only want the bullet on the FIRST li, here's what you're looking for:

.fr_contactInformation ul li.first strong:before
{
    content:url(/App_Themes/2011/images/hm_listImage.gif);
    padding-right: 20px;
}
like image 41
Alien Life Form Avatar answered Nov 01 '22 19:11

Alien Life Form


Thanks General Henry but that adds padding to the entire element.

I tried this and it worked:

      .fr_contactInformation ul li strong:before
       {
        content: url(/App_Themes/2011/images/hm_listImage.gif) "  ";

        }

By adding a some space in the inverted comments at the back of the img url, it created that gap I was looking for between the image element and the content.

Then I used a negative margin on the li to bring it back into place.

Thanks ;)

like image 22
Sixfoot Studio Avatar answered Nov 01 '22 18:11

Sixfoot Studio