Meek Meek - 3 months ago 15
CSS Question

Ul li with bullets made with ":before" - how to indent 2nd line of text

I have a list with up to four sub levels. Bullets are made with :before.
I have some trouble getting the 2nd line of text line up with the first one.

I have tried setting padding and text-indent like this:

ul {
padding-left: 1em;
text-indent: -1em;
}


- but it doesn't work. Setting
list-style-position: outside
doesn't seem to work either.

JSFIDDLE here

Any ideas?

Answer

Its better to use position: absolute instead of float to align bullets.

.menu {
  width: 250px;
}
ul.nav>li>a {
  position: relative;
}
/* First level */
ul.nav>li>a:before {
  position: absolute;
  font-family: 'Glyphicons Halflings';
  font-size: 7px;
  color: #901a1e;
  content: "\e080";
  border: 1px solid #d7d7d7;
  left: 0;
  top: 13px;
}
/* Sub levels */
ul.nav>li ul li>a {
  display: inline-block;
  vertical-align: top;
  padding-left: 10px;
  position: relative;
}
ul.nav>li ul li>a:before {
  position: absolute;
  font-size: 9px;
  color: #901a1e;
  content: "\25A0";
  left: 0;
  top: 3px;
}

ul li {
  list-style-type: none;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<div class="menu">
  <ul class="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">Sub menu here</a>
      <ul>
        <li><a href="#">Link 2.1 - one more very, very, very, long text</a></li>
        <li class="active"><a href="#">Link 2.2 - active</a></li>
        <li><a href="#">Link 2.3</a></li>
      </ul>
    </li>
    <li><a href="#">Separated link</a>
    </li>
    <li><a href="#">Separated link</a>
      <ul>
        <li><a href="#">Link 2.1</a>
          <ul>
            <li><a href="#">Link 3.1</a></li>
            <li><a href="#">Link 3.2</a></li>
            <li><a href="#">Link 3.3</a>
              <ul>
                <li><a href="#">Link 4.1 - one more very, very, very, long text</a></li>
                <li><a href="#">Link 4.2</a></li>
                <li><a href="#">Link 4.3</a></li>
              </ul>
            </li>
          </ul>
        </li>
      </ul>
    </li>
    <li><a href="#">One more very, very, very, long separated link</a></li>
    <li><a href="#">One more separated link</a></li>
  </ul>
</div>

Comments