How to align list items

Asked

Viewed 106 times

1

I have the following code:

ul {
  list-style: none;
  list-style-position: outside;
  padding-left: 0;
}

li {
  margin-bottom: 20px;
}

    li:before {
      content: "\2192";
      padding-right: 10px;
    }

p {
  display: inline;
}
<ul>
    <li><p>Item 1 alaksjd fçalksdj fçlaksjd fçlaksjd fçlkasdj flçkajsdlçkfjasldçkjflçaksd jfçlkasjd flçkajsdlkçf asd</p></li>
    <li><p>Item 2 adflçaksd jglçakhsd flaksdh kjahsdf gjhdfjkh skjchvçz,xckhvj çzlxkcjv zçlxckjvlçz xckjvçzlxkcjv</p></li>
    <li><p>Item 3 asdlçfkj asdlkfj çalsdjf</p></li>
</ul>

The result obtained is this:

inserir a descrição da imagem aqui

The desired result is this:

inserir a descrição da imagem aqui

Note: The red line is only to mark the alignment and does not part of the desired result.

You can do this via CSS?

1 answer

2


I believe that using the display: inline in the element p is what complicates everything. Alternatively, you can position the element li:before absolute form and set a left margin for the element p. Behold:

ul {
  list-style: none;
  list-style-position: outside;
  padding-left: 0;
}

li {
  margin-bottom: 20px;
  position: relative;
}

li:before {
  content: "\2192";
  padding-right: 10px;
  position: absolute;
}

p {
  margin-left: 20px;
}
<ul>
  <li>
    <p>Item 1 alaksjd fçalksdj fçlaksjd fçlaksjd fçlkasdj flçkajsdlçkfjasldçkjflçaksd jfçlkasjd flçkajsdlkçf asd</p>
  </li>
  <li>
    <p>Item 2 adflçaksd jglçakhsd flaksdh kjahsdf gjhdfjkh skjchvçz,xckhvj çzlxkcjv zçlxckjvlçz xckjvçzlxkcjv</p>
  </li>
  <li>
    <p>Item 3 asdlçfkj asdlkfj çalsdjf</p>
  </li>
</ul>

  • Thank you very much! Your answer helped me a lot, and I also managed to better understand how it works. I still don’t have a good relationship with CSS, rsrsrs... If you like challenges like this, here’s one more, haha... Greetings!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.