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

reference specific value inside of a class?

i’m trying to reference one part of a class in order to calculate something in another part of the code. i only want to reference the dimensions, nothing else. below, you will see cobra’s dimensional information is blank. i’m choosing arbitrary numbers and calculations – just trying to make it slightly "complicated" enough to explain a bit more. i hope this makes sense:

  • i want cobra’s width to equal viper’s width divided by 2.
  • i want cobra’s height to equal viper’s height exactly.
  • i want to be able to only change viper’s information and have
    cobra automatically update because it references viper
    .
.viper
 {
    width: calc((100px - 50px) * 3) / 2);
    height: 200px;
    font-family: garamond;
    font-color: black;

 }

.cobra
  {
    width:
    height:
    font-family: georgia;
    font-color: blue;
  }

>Solution :

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

If you are trying to accomplish this with JUST CSS, this can be accomplished quite easily using CSS variables.

First declare your viper’s width and height as a basis for a snake:

 :root{
  --viper-width: calc((100px - 50px) * 3) / 2);
  --viper-height: 200px;
 }

Then you give this variable to the equivalent properties of your snakes that you wish to modify in relation to the viper.

.cobra{
  width: calc(var(--viper-width) / 2);
  height: var(--viper-height);
  font-family: georgia;
  font-color: blue;
}

Then, any time you change your --viper-width and --viper-height variables, your .cobra will adjust accordingly.

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