Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple JavaScript code to help the public or an individual to customize and build your personal CSS framework #2905

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/).
Loading