> For the complete documentation index, see [llms.txt](https://petercheng7788.gitbook.io/developer-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://petercheng7788.gitbook.io/developer-note/frontend/css.md).

# CSS

## Chain of css syntax

```css
// single class with multiple conditions
div.test {
    background-color: yellow;
}
.flex-container >div.red1{
    background-color: red;
}
.red1.red2{
    background-color: red;
}

// multiple class share same css
.red1,.red2 {
     background-color: red;
}
```

## CSS Specificity

* The final css result is due to total mark of css, style with higher marks win
* CSS mark counting can be separated into different slot

### Element Selector (Slot 1)

<figure><img src="/files/fJLY93cuSb4g4uXfzz2V" alt=""><figcaption></figcaption></figure>

### Class Selector (Slot 2)

<figure><img src="/files/wUxa6Bgu9qStmsA37TVx" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/n6JOIKvKONopAmYww1qx" alt=""><figcaption></figcaption></figure>

### ID Selector (Slot 3)

<figure><img src="/files/WnqZOwy3D7ghCn8wggTT" alt=""><figcaption></figcaption></figure>

### Inline Style (Slot 4)

<figure><img src="/files/MF09enc9iS3DWDt3jmXH" alt=""><figcaption></figcaption></figure>

## BEM Naming

`{block}_{element}--{modifer}`

[`https://getbem.com/naming/`](https://getbem.com/naming/)

## CSS Module

* CSS Modules locally scope CSS by automatically creating a unique class name. This allows you to use the same class name in different files without worrying about collisions

## Pre-processor

* It is a tool or programming language that extends the capabilities of CSS (Cascading Style Sheets) by introducing additional features, e.g: sass
* the code is compiled into regular CSS that can be used by web browsers. This compilation process typically involves running a preprocessor-specific command or using a build tool like webpack or gulp.

## Post CSS

* PostCSS is not a preprocessor, but a post-processor. That means it does not have its own syntax, but instead uses standard CSS and modifies it with javascript plugin
* Then it compile to pure css which is same as pre-processor

<figure><img src="/files/j0da7v55sZJKztOOm3nn" alt=""><figcaption></figcaption></figure>

* The processor will compile through the plugin that defined in the file

```bash
npm install autoprefixer postcss postcss-cli
```

{% code title="postcss.config.js" %}

```javascript
module.exports = {
  plugins: {
    autoprefixer: {},
  }
}
```

{% endcode %}

* Compile

```
npx postcss styles.css -o dist/styles.css
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://petercheng7788.gitbook.io/developer-note/frontend/css.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
