작성
·
48
·
수정됨
0
안녕하세요 강사님
typescript next 환경에서 포트폴리오를 만들고 있는데요
위 사진처럼 nested list 구조 일때 불릿 스타일이 변하지 않습니다.
tailwind.config.ts 에서 기본 ul 태그 스타일을 수정해볼까 하는데
ul {
list-style-type: disc;
}
ul ul {
list-style-type: circle;
}
ul ul ul {
list-style-type: square;
}
이런식(?)으로요
특정 요소만 기본 css 를 사용하고 싶거나 위 처럼 tailwind 스타일을 커스텀하고 싶을때 어떻게 하면될까요?
답변 2
0
Tailwind CSS에서 중첩된 리스트의 불릿 스타일을 다르게 지정하려면 몇 가지 방법이 있습니다.
globals.css
파일에 직접 CSS를 추가하는 방법입니다:
/* globals.css 파일에 추가 */
ul {
list-style-type: disc;
}
ul ul {
list-style-type: circle;
}
ul ul ul {
list-style-type: square;
}
tailwind.config.ts
파일을 수정하여 스타일을 지정할 수 있습니다:
import type { Config } from "tailwindcss";
const config: Config = {
// 기존 설정...
theme: {
extend: {
// 기존 확장...
},
},
plugins: [
function({ addBase }) {
addBase({
'ul': { listStyleType: 'disc' },
'ul ul': { listStyleType: 'circle' },
'ul ul ul': { listStyleType: 'square' },
})
}
],
};
export default config;
addBase
플러그인 함수를 사용하면 기본 스타일을 추가할 수 있습니다.
특정 컴포넌트에만 적용하고 싶다면, 클래스를 만들어 사용할 수도 있습니다:
// tailwind.config.ts
import type { Config } from "tailwindcss";
const config: Config = {
// 기존 설정...
theme: {
extend: {
// 기존 확장...
},
},
plugins: [],
};
export default config;
그리고 globals.css
에 다음과 같이 추가:
/* globals.css */
@layer components {
.nested-list ul {
list-style-type: disc;
}
.nested-list ul ul {
list-style-type: circle;
}
.nested-list ul ul ul {
list-style-type: square;
}
}
그런 다음 컴포넌트에서:
<div className="nested-list">
<ul>
<li>항목 1
<ul>
<li>하위 항목 1.1
<ul>
<li>하위 하위 항목 1.1.1</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>