DEV Community

ThajudeenKT
ThajudeenKT

Posted on

I need to reduce or alter the font size of parent class based on the font size of span tag inside child class

<div class="heading">
  <p>Hero<br>
<span style="font-size:20px;">Banner</span><br>
Text</p>
</div>
Enter fullscreen mode Exit fullscreen mode
.heading {
  font-size: 8.4rem;
  line-height: 7.56rem;
}

Enter fullscreen mode Exit fullscreen mode
const elements = document.body.querySelectorAll("*[style]")
elements.forEach(element=>{
 if(element.style.fontSize){
   const {value: size, unit} = element.attributeStyleMap.get('font-size')
   element.attributeStyleMap.set('line-height', CSS[unit](Math.floor(size * (8.4/7.56))))
   }
   })
Enter fullscreen mode Exit fullscreen mode

Here I can remove only the space below the span tag but not the space above the span tag. Please help to remove the same

Top comments (1)

Collapse
 
brampayrequest profile image
Bram Hammer

You could use css variables.
So for example

:root { --fs: 8.5rem; }
.heading {
    font-size: calc( --fs * 3 );
}
.heading p span {
    font-size: --fs;
}
Enter fullscreen mode Exit fullscreen mode

And change the --fs value for certain screen sizes?