Home > Software design >  How can I keep the state of an element after clicking?
How can I keep the state of an element after clicking?

Time:08-18

I have a menu with 2 labels the user can click on. When you hover over the labels you get a animation of two lines animating to the top and bottom of the chosen label - When you click on the label and leave the area with your mouse, the lines will go back to their start position - I want the lines to stay on that position when the label is clicked and not to go back on their start position. I tried :active or :focus but that didn't work out.

body {
  background-color: #000;
}

figure.title-line {
  position: relative;
  margin: 10px;
  min-width: 230px;
  max-width: 315px;
  width: 100%;
  color: #ffffff;
  text-align: center;
  font-size: 16px;
}

figure.title-line *:before,
figure.title-line *:after {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-transition: all 0.55s ease;
  transition: all 0.55s ease;
}

figure.title-line .title {
  position: absolute;
  top: -8px;
}

figure.title-line .title:before,
figure.title-line .title:after {
  height: 2px;
  position: absolute;
  content: '';
  background-color: #ffffff;
}

.title:before,
.title:after {
  opacity: 0;
}

.title:hover::before,
.title:hover::after {
  opacity: 1;
}

figure.title-line .title:before {
  top: 0;
  right: 0px;
  width: 186px;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  -moz-transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  -o-transform: translateX(-50%);
}

figure.title-line .title:after {
  bottom: 0;
  left: 0px;
  width: 260px;
  -webkit-transform: translateX(50%);
  transform: translateX(50%);
  -moz-transform: translateX(50%);
  -ms-transform: translateX(50%);
  -o-transform: translateX(50%);
}

figure.title-line a {
  margin: 0;
}

figure.title-line:hover .title:before,
figure.title-line.hover .title:before,
figure.title-line:hover .title:after,
figure.title-line.hover .title:after,
figure.title-line:hover .title div:before,
figure.title-line.hover .title div:before,
figure.title-line:hover .title div:after,
figure.title-line.hover .title div:after {
  -webkit-transform: translate(0, 0);
  transform: translate(0, 0);
}

figure.title-line:hover .title:before,
figure.title-line.hover .title:before,
figure.title-line:hover .title:after,
figure.title-line.hover .title:after {
  -webkit-transition-delay: 0.15s;
  transition-delay: 0.15s;
}
<figure >
  <div >
    <div>
      <a >EXAMPLE</a>
    </div>
  </div>
</figure>
<figure >
  <div >
    <div>
      <a >EXAMPLE2</a>
    </div>
  </div>
</figure>

CodePudding user response:

According to this : https://www.w3schools.com/cssref/css3_pr_animation-fill-mode.asp

add this to your CSS code

.title pos,.title{
animation-fill-mode: forwards;
}

CodePudding user response:

First which line do you want? I think you can just tap on this line that you wont and when you tap they have some window that open, in said there have a list for option you can choose and then you tap on this line, or the easier its to click on the left side where the number of line start.

  • Related