# CSS와 JavaScript

> 🚫대부분 스타일의 경우 자바스크립트로 CSS 조작 하는 것보다 CSS로 하는 것이 좋습니다.

1. JavaScript로 CSS 설정

   ```javascript
     document.querySelector("selectors").style.backgroundColor = "yellow";
     document.querySelector("selectors").style.WebkitOverflowScrolling = "touch" | "auto;
   ```
2. JavaScript로 *읽기 전용* CSS 객체([CSSStyleDeclaration](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration)) 반환

   ```javascript
     window.getComputedStyle(element[, pseudoElt]);

     let div = document.querySelector('div');
     let color = window.getComputedStyle(div).getPropertyValue('color');
   ```
3. JavaScript로 CSS **너비**, **높이** 값 탐색

   ![](/files/-MaQx8WgXxFqTXYN5Bop)

   ```javascript
   document.querySelector("selectors").offsetWidth;
   document.querySelector("selectors").clientHeight;
   document.querySelector("selectors").scrollWidth;
   ```

   ![](/files/-MaQx8WhY5VZU_9tZMhr)

   ```javascript
   window.innerWidth; // border 내부 너비
   window.innerHeight; // border 내부 높이
   ```

   ※ `innerWidth`, `innerHeight`는 읽기 전용

   * 너비, 높이 변경: [`window.resizeTo`](https://developer.mozilla.org/en-US/docs/Web/API/Window/resizeTo)

   ![](/files/-MaQx8WiOu3BewiOL4DP)

   ```javascript
   window.screen.availWidth; // 실제 사용 가능한 화면 너비
   window.screen.availHeight; // 실제 사용 가능한 화면 높이
   ```

## Reference

[getComputedStyle | MDN](https://developer.mozilla.org/ko/docs/Web/API/Window/getComputedStyle)

[요소 사이즈와 스크롤 | JS Info](https://ko.javascript.info/size-and-scroll)

[CSS와 관련된 자바스크립트](https://www.zerocho.com/category/JavaScript/post/5aa23cd4e70ee8001bc60b9a)


---

# Agent Instructions: 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:

```
GET https://yong2401.gitbook.io/til-by-ellie/css-1/css_js.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
