Skip to content

Commit

Permalink
JavaScript code on how to customize and build your personal CSS frame…
Browse files Browse the repository at this point in the history
…work.

code on how to build your CSS framework using JavaScript document and map
  • Loading branch information
emmanuel-455 authored Feb 18, 2024
1 parent 51a37d0 commit 1b2cbbf
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion css-in-javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
1. [Nesting](#nesting)
1. [Inline](#inline)
1. [Themes](#themes)

1. [Building-your-CSS-framework-using-JavaScript-document](#JavaScript-document)

## Naming

- Use camelCase for object keys (i.e. "selectors").
Expand Down Expand Up @@ -427,6 +428,41 @@
});
```
## JavaScript-document
- Using javaScript document to customize you CSS framework and use it personally whenever you are building projects*
> This is just an important code that can help you to achieve that.
- Finding the element by tagName and looping through them and then writing some if statement code based on the classlist contain and styling the class name based on what style you want it to be.
```js

//bad

let theTagName = document.querySelector("h1");
// Loop through all h1 elements
for (let i = 0; i < theTagName.length; i++) {
let element = theTagName[i];
// Check if the element has the class "b-red"
if (element.classList.contains("b-red")) {
// Apply style if the class is present
element.style.color = "red";
}}
}

// good

let theTagName = document.getElementsByTagName("h1");
// Loop through all h1 elements
for (let i = 0; i < theTagName.length; i++) {
let element = theTagName[i];

// Check if the element has the class "b-red"
if (element.classList.contains("b-red")) {
// Apply style if the class is present
element.style.color = "red";
}};
```
---
CSS puns adapted from [Saijo George](https://saijogeorge.com/css-puns/).

0 comments on commit 1b2cbbf

Please sign in to comment.