For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Sunday, March 10, 2024

Apply CSS via JavaScript

 

Here is the example where apply css via JavaScript

<script>

const mstyle = document.head.appendChild(document.createElement(‘style’));
style.textContent = /*this is the css*/`

.myclass {
aspect-ratio: 16 / 9; background-color: #000;
position: relative; display: block; contain: content;
background-position: center center;
background-size: cover;

}

#mydivid {
color:green; opacity: 0;
}
`;

</script>

Share:

Ads Inside Post

Powered by Blogger.

Archive