Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you set CSS property values when another element is active in CSS?

I’m currently working on a no JavaScript light switch. One of the issues I’m having is the fact that I don’t know how to set a property of something else while one thing is :active. I’ve been trying a few things, but nothing is working. I have the CodePen right here. Otherwise, here’s some code:

body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: gray;
  overflow: hidden;
  filter: brightness(100%);
}

.wall-switch {
  background-color: #ebebeb;
  width: 300px;
  height: 500px;
  box-shadow: inset -10px -10px 22px 0px rgba(255, 255, 255, 1), inset 10px 10px 22px 0px rgba(0, 0, 0, 0.30);
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 25px;
  border-radius: 4px;
}

.screw {
  padding: 7.5px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 2.5px 2.5px 10px 0px rgba(255, 255, 255, 1), inset -2.5px -2.5px 10px 0px rgba(0, 0, 0, 0.30), 0px 0px 2px 1px rgba(0, 0, 0, 0.40);
}

.icon {
  transition-duration: 10s;
  transition-timing-function: linear;
}

.icon:active {
  transform: rotate(-3600deg);
}

.padding {
  padding: 55px;
}

.switch {
  width: 105px;
  height: 200px;
  box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.40), inset 0px 95px 20px 0px #ebebeb, inset 0px -95px 20px 0px rgba(0, 0, 0, 0.20);
  border-radius: 2.5px;
}

.switch:active {
  box-shadow: 0px 0px 2px 1px rgba(0, 0, 0, 0.40), inset 0px -95px 20px 0px #6b6b6b, inset 0px 95px 20px 0px rgba(0, 0, 0, 0.20);
}

.switch:active .wall-switch {
  background-color: #6b6b6b;
}
<div class="wall-switch">
  <div class="screw">
    <svg class="icon  icon--plus" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" fill="rgba(0, 0, 0, 0.45)">
        <path d="M24 10h-10v-10h-4v10h-10v4h10v10h4v-10h10z" stroke="url(#grad1)" />
    </svg>
  </div>
  <div class="padding"></div>
  <div class="switch"></div>
  <div class="padding"></div>
  <div class="screw">
    <svg class="icon  icon--plus" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg" fill="rgba(0, 0, 0, 0.45)">
        <path d="M24 10h-10v-10h-4v10h-10v4h10v10h4v-10h10z" stroke="url(#grad1)" />
    </svg>
  </div>
</div>

Anyone know of a solution? I’ve been working on this for a while now.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I looked it up, turns out its a new feature in css. The > character is for ascension (child to parent, which is new).

.wall-switch:has(> .switch:active){
  background-color: #6b6b6b;
}

Reference: Is there a CSS parent selector?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading