Css style

Create Forward, Backward Buttons – HTML & CSS – SitePoint Forums

My attempt here: https://jsfiddle.net/oawxpzj4/1/

Try making a copy of this: https://jsfiddle.net/oawxpzj4/

How should this CSS have been written instead?

.exit {
  display: inline-block;
  width: 64px;
  height: 64px;
  border: 8px solid #333;
  border-radius: 50%;
  margin-right: 24px;
}

.exit::after {
  content: '';
  display: inline-block;
  margin-top: 16.8px;
  margin-left: 9.6px;
  width: 22.4px;
  height: 22.4px;
  border-top: 8px solid #333;
  border-right: 8px solid #333;
  -moz-transform: rotate(-135deg);
  -webkit-transform: rotate(-135deg);
  transform: rotate(-135deg);
}


.exit.exitPage2 {
  display: inline-block;
  width: 64px;
  height: 64px;
  border: 8px solid #333;
  border-radius: 50%;
  margin-left: 24px;
}

.exit.exitPage2::after {
  content: '';
  display: inline-block;
  margin-top: 16.8px;
  margin-left: -9.6px;
  width: 22.4px;
  height: 22.4px;
  border-top: 8px solid #333;
  border-right: 8px solid #333;
  -moz-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.exit.exitPage3 {
  display: inline-block;
  width: 64px;
  height: 64px;
  border: 8px solid #333;
  border-radius: 50%;
  margin-right: 24px;
}

.exit.exitPage3::after {
  content: '';
  display: inline-block;
  margin-top: 16.8px;
  margin-left: 9.6px;
  width: 22.4px;
  height: 22.4px;
  border-top: 8px solid #333;
  border-right: 8px solid #333;
  -moz-transform: rotate(-135deg);
  -webkit-transform: rotate(-135deg);
  transform: rotate(-135deg);
}

a:hover .exit,
a:hover .exit.exitPage2,
a:hover .exit.exitPage3 {
  border: 8px solid #e74c3c;
}

a:hover .exit::after,
a:hover .exit.exitPage2::after,
a:hover .exit.exitPage3 {
  border-top: 8px solid #e74c3c;
  border-right: 8px solid #e74c3c;
}

  
  

  
  

  
  


Don’t repeat unnecessary rules all the time. This makes the code much more difficult to use.:slight_smile:

You only need this:

.exit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 8px solid #333;
  border-radius: 50%;
  margin-right: 24px;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}

.exit::after {
  content: '';
  width: 22px;
  height: 22px;
  border-top: 8px solid #333;
  border-right: 8px solid #333;
  transform: rotate(-135deg);
  margin-left: 9px;
}

.exit.exitPage2 {
  margin-left: 24px;
}

.exit.exitPage2::after {
  margin-left: -9px;
  transform: rotate(45deg);
}

Note that the following rules can never be used in your page.

a:hover .exit,
a:hover .exit.exitPage2,
a:hover .exit.exitPage3 {
  border: 8px solid #e74c3c;
}

a:hover .exit::after,
a:hover .exit.exitPage2::after,
a:hover .exit.exitPage3 {
  border-top: 8px solid #e74c3c;
  border-right: 8px solid #e74c3c;
}

A button (.exit) element cannot be wrapped in an anchor (or vice versa). They are two interactive elements that cannot be nested inside each other.

How can I do the hover stuff then?

Don’t I need exitPage3?

Is there a difference in the code for exitPage3 that is not already provided by .exit?

You know that :slight_smile:

.exit:hover {
  border: 8px solid #e74c3c;
}

.exit:hover::after {
  border-top: 8px solid #e74c3c;
  border-right: 8px solid #e74c3c;
}



1 like

It would then be changed into what then?
I don’t understand how I would remove exitPage3

Can you show me how it would be done, because I still don’t understand. https://jsfiddle.net/x7gv5Ltn/

I still don’t think it can be removed, I can’t figure it out.

Currently:

If you are in .container1 exitPage3 takes you to page3 exitPage2 takes you to page 2

      
      

If you are in .container2 the exit takes you to Page 1 exitPage3 takes you to page3

        
        

If you are in .container3 exitPage2 takes you to page 2 the exit takes you to Page 1

        
        

And then here, exitPage3 would be changed to exitPage2?

I still do not understand.

  function exitClickHandler(e) {
    if (e.target.classList.contains("exit")) {
      document.querySelector(".container2").classList.add("hide");
      document.querySelector(".container3").classList.add("hide");
      document.querySelector(".container1").classList.remove("hide");
      console.log('Page1');
    }
    if (e.target.classList.contains("exitPage2")) {
      document.querySelector(".container1").classList.add("hide");
      document.querySelector(".container3").classList.add("hide");
      document.querySelector(".container2").classList.remove("hide");
      console.log('Page2');
    }
    if (e.target.classList.contains("exitPage3")) {
      document.querySelector(".container2").classList.add("hide");
      document.querySelector(".container1").classList.add("hide");
      document.querySelector(".container3").classList.remove("hide");
      console.log('Page3');
    }
    window.scrollTo(0, 0);
  }

You can’t remove it because the js uses it. You don’t need to have it in the css file because the styles are provided by .exit.



2 likes