Antoine
Antoine

Reputation: 165

Css Triangle displayed at the bottom of the page

I wish to have a triangle displayed under each item as I hover it. So far it works (even though I don't really understand how) but my problem is I also have the same triangle displayed at the bottom... I don't get why and I can't get rid of it. Any enlightment would be very appreciated, here's my code

.wrapper_icons {
  list-style: none;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
}
.wrapper_icons li {
  border-bottom: 4px solid black;
  flex: 3;
  margin-right: 20px;
}
li:after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  width: 0;
  height: 0;
  border: solid transparent;
  margin-left: -11px;
  border-width: 11px;
  border-top-color: rgba(0, 0, 0, 0.2);
}
.wrapper_icons li:hover {
  cursor: pointer;
  cursor: hand;
}
.sink {
  display: inline-block;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: -webkit-transform;
  transition-property: transform;
}
.sink:hover {
  -webkit-transform: translateY(5px);
  -ms-transform: translateY(5px);
  transform: translateY(5px);
}
<ul class="wrapper_icons">
  <li class="sink">Lorem ipsum</li>
  <li class="sink">Lorem ipsum</li>
  <li class="sink">Lorem ipsum</li>
</ul>

Upvotes: 0

Views: 44

Answers (2)

Nenad Vracar
Nenad Vracar

Reputation: 122145

You can just create transparent triangle with pseudo-element and change its color when you hover that li with li:hover:after

.wrapper_icons {
  list-style: none;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
}
.wrapper_icons li {
  border-bottom: 4px solid black;
  flex: 3;
  margin-right: 20px;
}
li:after {
  content: '';
  position: absolute;
  top: calc(100% + 4px);
  transform: translateX(-50%);
  left: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 7px 0 7px;
  border-color: transparent;
  transition: all 0.3s ease-in;
}
.wrapper_icons li:hover {
  cursor: pointer;
}
.sink {
  transition: all 0.3s ease-in;
}
.sink:hover {
  transform: translateY(5px);
}
.sink:hover:after {
  border-top-color: rgba(0, 0, 0, 0.2);
}
<ul class="wrapper_icons">
  <li class="sink">Lorem ipsum</li>
  <li class="sink">Lorem ipsum</li>
  <li class="sink">Lorem ipsum</li>
</ul>

Upvotes: 1

Kees van Lierop
Kees van Lierop

Reputation: 1013

The after pseudo-elements position is set to absolute, so it will take the position from its first parent with position: relative. So therefore add position: relative to the list item:

.wrapper_icons li 
{
    position: relative;
    border-bottom:4px solid black;
    flex:3;
    margin-right:20px;
}

Upvotes: 1

Related Questions