Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove active and focus from element on second click

Tags:

css

I'm trying to make an interactive map with information on it. When you click on a dot it is resized and shows some contacts. This is achieved because the element gets the :active and :focus pseudo-classes.

Is there any way to remove the pseudo-classes from the element when it is clicked a second time? In effect, is it possible make element close when it is clicked again?

.distribution-map {
  position: relative;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  margin: 0 auto;
}
.distribution-map .map-point {
  cursor: pointer;
  outline: none;
  top: 20px;
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 20px;
}
.distribution-map .map-point:active,
.distribution-map .map-point:focus {
  margin: 0;
  padding: 0;
  filter: opacity: 1;
  width: 300px;
  height: 220px;
  color: #e5e5e5;
  z-index: 1;
  -webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
  transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
}
<div class="distribution-map">
  <button class="map-point">
  </button>
</div>
like image 497
Bogdan Tushevskyi Avatar asked Sep 16 '16 09:09

Bogdan Tushevskyi


People also ask

How do I get rid of focus on buttons on click?

To remove focus around the button outline:none property is used. Outline property: Outline is an element property which draws a line around element but outside the border. It does not take space from the width of an element like border.

How do you remove focus from an element?

The blur() method removes focus from an element.

How do you keep active CSS style after clicking a button?

The :active selector is used to select and style the active link. A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links.

How do you turn off focus in CSS?

To remove or disable focus border of browser with CSS, we select the styles for the :focus pseudo-class. to set the outline style to none to remove the border of the element that's in focus.


1 Answers

This can be achieved with pointer-events: none;

By adding pointer-events: none; to the focused element you can stop mouse interaction on the element so effectively it becomes unfocused on the next click.

The following modifications are required:

  • Add pointer-events: none; to .distribution-map .map-point:active, .distribution-map .map-point:focus

.distribution-map {
  position: relative;
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  margin: 0 auto;
}
.distribution-map .map-point {
  cursor: pointer;
  outline: none;
  top: 20px;
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 20px;
}
.distribution-map .map-point:active,
.distribution-map .map-point:focus {
  margin: 0;
  padding: 0;
  filter: opacity: 1;
  width: 300px;
  height: 220px;
  color: #e5e5e5;
  z-index: 1;
  -webkit-transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
  transition: opacity 0.25s ease-in-out, width 0.25s ease-in-out, height 0.25s ease-in-out;
  pointer-events: none;
}
<div class="distribution-map">
  <button class="map-point">
  </button>
</div>
like image 200
Hidden Hobbes Avatar answered Oct 27 '22 19:10

Hidden Hobbes