I am trying to style a list so that there are vertical lines shown until the end of the list if a child element is present.
Here’s the list HTML:
<ul>
<li>list item
<ul>
<li>list item</li>
<li>list item 2</li>
</ul>
</li>
<li>second list
<ul>
<li>list item</li>
</ul>
</li>
</ul>
It should look like this:
I tried adding a border on the left, but I do not know how I can change where the border starts.
This .css file:
ul {
border-left: 1px solid;
}
results in
How can I align the left border to start below the bullet? And how can I remove the leftmost border?
4
Answers
Try This:
Explanation:
Answer: it might be a hacky way but I added
margin-left: -14px;
to move the element a bit to the left (backward space)Answer: I just didn’t style the parent list so it doesn’t have the border style.
Note: I added
padding-left: 30px;
for styling purposes.You can create a
pseudo
-element on each nestedul
to create a new line between eachul
.Use this selector if you don’t want a line on the last
ul
:Use this selector if you want a line on the last
ul
:You can get a similar effect, by using some of pseudo elements.
There is a property
list-style-position: inside
which moves your bullet points inside the content box of theul
: