Home > Software engineering >  Check with CSS what style is applied
Check with CSS what style is applied

Time:09-27

I am looking for the next scenario in css where i will be able to check if a style is applied without using any javascript code.
Example: If flex: wrap is applied add another style like gap: 5. All this computations should be done using only css.
I inspected the documentation but i did not find something similar. Could somebody help?

CodePudding user response:

You can directly use the "gap" css. If there is a flex property used, only then the gap property will work. So no harm in using the gap property by default. Why check for whether flex is used or not.

CodePudding user response:

as far as I understand, to check a style is applied, it must use javascript code, ex:

const box = document.getElementById('box');

//  Check if CSS property is contained in Style
if (box.style.backgroundColor) {
  console.log('value is', box.style.backgroundColor);
} else {
  console.log('CSS property is not contained in style');
}
  •  Tags:  
  • css
  • Related