-3

I want to create a triangle below the center of each li element but not the last one.

html

<ul class="steps-ul">
  <li> Step 1: Hardware Mounting </li>
  <li> Step 2: Hardware Connection </li>
  <li> Step 3: Devices Connection </li>
  <li> Step 4: Initial Test </li>
</ul>

css

.steps-ul {
  list-style-type: none;
  width: 500px;
  text-align: center;
}

.steps-ul li:nth-child(odd) {
  background-color:#efefef;
}
.steps-ul li:nth-child(odd)::after {
  border-top: 20px solid #efefef;
}
.steps-ul li {
  margin: 20px;
  padding: 10px;
  font-size: 1.5em;
  background-color:#d7d7d7;
}
.steps-ul li::after {
  position: absolute;
  left: 270px;
  margin-top: 30px;
  width: 0; 
  height: 0; 
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid #d7d7d7;
}

Heres a screenshot of what i would like to accomplish

I attempted using the ::after psuedo element within css but no results.

  • Your `::after` selector needs `content`, this can be a single space `" "`, in order to display it. – Apodemus Apr 06 '23 at 15:03
  • great! thank you so much. that and adding `position: absolute` got my little box showing. Im sure i can take it from here. – Aaron Russell Apr 06 '23 at 15:08
  • 1
    You are required to post a [mcve] here, **within your question**, and [not a link](https://meta.stackoverflow.com/a/254430/162698) to any other site. – Rob Apr 06 '23 at 21:07
  • This question did not require debugging. – Aaron Russell Apr 07 '23 at 20:49
  • 2
    You can edit your question and instead of codepen you can use code snippets in Stackoverflow. – Apodemus Apr 07 '23 at 21:56
  • 1
    @AaronRussell You are to post your code **here within your question and not a link to any other site** – Rob Apr 07 '23 at 23:49

1 Answers1

-1

Your ::after selector is missing a content property, which is required for pseudo elements to be displayed.

.steps-ul li::after {
  content: " ";
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 100px solid red;
}

Copied the triangle code from this question.

As for not adding the triangle to the last element, you can use the :not(:last-child) selector.

Apodemus
  • 579
  • 2
  • 19