Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapse arrow on mouse click

I have this example of Collapse row on mouse click:

jsfiddle.net/7bz5au97/

I would like to ask you how I can add arrow like this one at the beginning of the question and rotate it when the question is expanded?

enter image description here

Can this be done with CSS only or I need also to add JavaScript?

like image 628
Peter Penzov Avatar asked Sep 16 '25 11:09

Peter Penzov


1 Answers

You could do this almost entirely with css:

var arr = document.querySelector('.arrow');
arr.addEventListener('click', function(event) {
  event.target.classList.toggle('down');
});
.arrow {
  margin: 1em;
}

.arrow::before {
  position: absolute;
  content: '';
  width: 0;
  height: 0;
  border: .5em solid transparent;
  border-left-color: gray;
  transform-origin: 0 50%;
  transition: transform .25s;
}

.arrow.down::before {
  transform: rotate(90deg);
  transition: transform .25s;
}
<div class="arrow"></div>
like image 112
ray hatfield Avatar answered Sep 18 '25 04:09

ray hatfield