사이트에서 사용자 지정 CSS 변경하기

:bookmark: 이 가이드는 CSS 소개, Discourse에서 CSS를 추가하는 위치, 그리고 브라우저 검사 도구를 사용하여 올바른 선택자를 찾는 방법 등을 포함하여 Discourse 사이트에서 CSS를 변경하는 방법을 설명합니다.

:person_raising_hand: 필요한 사용자 권한: 관리자

요약

이 가이드에서는 다음 내용을 다룹니다:

  1. CSS 및 핵심 개념에 대한 간단한 소개
  2. 테마 구성 요소를 사용하여 Discourse 사이트에 CSS를 추가하는 방법
  3. 브라우저 검사 도구를 사용하여 올바른 CSS 선택자를 찾는 방법

CSS 기초 이해하기

CSS는 Cascading Style Sheets(캐스케이딩 스타일 시트)의 약자입니다. 이해해야 할 세 가지 핵심 개념은 다음과 같습니다:

  1. 구조: CSS 규칙은 선택자, 속성, 값으로 구성됩니다.
p {
  color: red;
}
  1. 캐스케이딩: 마지막으로 적용된 규칙이 우선합니다. 예를 들어:
p {
  color: red;
}
p {
  color: green;
}

마지막으로 적용된 규칙이므로 단락은 녹색이 됩니다.

  1. 특이성(Specificity): 더 구체적인 규칙이 덜 구체적인 규칙을 덮어씁니다. 예를 들어:
div p {
  color: green;
}
p {
  color: red;
}

div pp보다 더 구체적이므로 div 안의 단락은 녹색으로 유지됩니다.

Discourse 사이트에 CSS 추가하기

Discourse 사이트에 CSS를 추가하려면:

  1. 관리자 탐색 사이드바에서 Appearance > Themes & components(모양 > 테마 및 구성 요소)로 이동하고 Components(구성 요소) 탭을 클릭합니다. (또는 사이트의 이 URL을 따르세요: https://yoursite.com/admin/config/customize/components)

  2. Install(설치)을 클릭한 다음 :heavy_plus_sign: Create New(새로 만들기)를 클릭합니다

  3. 테마 구성 요소 이름을 지정한 다음 Create (만들기)를 클릭합니다

  4. 구성 요소가 적용될 테마를 선택한 다음 녹색 체크표시 아이콘을 클릭하여 선택 사항을 저장합니다

:warning: 여러 개의 사용자 선택 가능 테마가 있는 경우, 테마 구성 요소를 모든 관련 테마에 추가했는지 확인하세요.

  1. Edit Code(코드 편집)를 클릭합니다

  2. CSS 탭에 CSS를 추가합니다

  3. 변경 사항을 적용하려면 “Save”(저장)를 클릭합니다.

올바른 CSS 선택자 찾기

올바른 CSS 선택자를 찾기 위해 브라우저 검사 도구를 사용하세요:

  1. 수정하려는 요소에서 마우스 오른쪽 버튼을 클릭합니다.

  2. 컨텍스트 메뉴에서 “Inspect”(검사)를 선택합니다.

  3. 개발자 도구 패널에서 요소 선택자를 찾습니다.

  4. 해당 선택자를 클릭하고 CSS 규칙을 추가합니다.

  5. 규칙을 복사하여 테마 구성 요소의 CSS 섹션에 붙여넣고 충돌하는 규칙을 제거합니다.

더 구체적인 선택자가 필요한 경우, Discourse의 기존 스타일에 사용된 선택자를 복사하여 테마 구성 요소에서 수정해야 할 수 있습니다.

위 단계를 시연하는 영상이 있습니다:

문제 해결

변경 사항이 적용되지 않는 경우, 다음 사항을 확인하세요:

  • 테마 구성 요소가 모든 관련 테마에서 활성화되어 있는지
  • 기존 스타일을 덮어쓸 만큼 CSS 규칙이 충분히 구체적인지

추가 리소스

41개의 좋아요
Policy notice: no basic HTML / CSS questions please
How can hide the 'Latest', 'Top', 'Badges' and 'Categories' in the hamburger menu?
Anyway to style discourse topic title? ( IE, red, bold, highlight, anything. )
Remove background color change after page loading
How to make pinned items have less text underneath them
Customising Login Page
How to disable all alert banners in discourse
Notification color: light blue
🌐 www theme
Cloudfront cdn with discourse?
How to change search banner headline font size?
How to reduce the size of category logo image
Can I make a custom button with CSS and HTML?
Applying Scroll Bar (Horizontal & Vertical) to Code Snippets
Hide suspension status
How can I hide the add button from sidebar
Forum homepage, how to make full screen?
Customizing FAQs and Guidelines
Switching the discourse color scheme: Changing Red Hues in CSS
How can i disable categories on home page?
Selected Quote Background Color
How to remove bottom bar from all topics
Disable bio, location and profile picture
Prevent users from changing their Full Names
Line under avatar?
Custom CSS/HTML in non-default theme (without component)
Edit or Disable "community" in sidebar menu
How do I change text color in my Header?
Customize posts' contents with your own styles
Toolbar under site header per category
How to hide 0 votes?
Change Default Badge Colors (Bronze, Silver, Gold)
Search section like on Reddit?
How to hide a button (SVG icon) if user is logged in?
Change the headings of preferences settings
How to change layout of login screen
Can you change the color of customizable text?
Policy notice: no basic HTML / CSS questions please
How to resize 'Modern Category + Group Boxes' thumbnail via CSS
Category List with Banners
Customize Login pop-up box?
How do I disable the hot feature?
Search Banner image cuts off on smaller screens
"Reader Mode" theme component feedback
Finding CSS selectors for page layout, user groups
How to change the buttons' colors on hover?
How to remove Tos and privacy from ui?
How to add separator lines to the Welcome Banner sections?
Understanding link click counters
Watching category mandatory
Show Only Categories on Mobile View
Change URL or remove Powered by Discourse
Wishlist: visual cue for "user got a badge for this post"
Remove "pinned" button at bottom of topic
How to style category boxes?
vBulletin Emojis
Can We Represent Our Categories Like This on a Discourse Hosted Community
How to Edit the Menu Design and User Profile Design
Rounded login buttons
How can I make the home page similar to this one?
How do I add CSS?
Show sidebar to anonymous user + Welcome area in central theme
Remove search from the header
Replies and Views Orange Color, help!
Differentiate Admin and Moderator Shield Icons
How to use CSS for versatile-banner
Extra spaces within text
Turn off the “views” on topic
CSS edits not being applied on mobile
How to make login and registration pages look like this?
How do I move an image/banner to the VERY top of the page?
Theme Identification
How to customize the composer toolbar?
Which path or file handles the custom template CSS?
Help with locating the correct CSS location to change color of specific text
Daily Summary (1pm UTC)
Category description floating to the right
FKB Pro - Social theme
Is it possible to change via CSS the Category Moderator shield?
Top contributors sidebar Backgound
Ocultar menú flotante
Which is Better? Discourse or Flarum?
Is there a way to link replies after they are posted?
Customize User Cards
Change hover background color for nav class buttons
Allow “Name" field to be disabled in registration dialog
Adding a table to your post using markdown
How can discourse administrators turn off personal messages
How to change/remove icon on login screen?
Advanced Header Search
Versatile Banner
Versatile Banner
Homepage Feature
Removing edit history pencil icon
Howto add a GAP between Categories
How can I add a menu item
Can't remove topic footer buttons on iOS
Support for Umami analytic
Hiding empty votes via plugin options
New default nav style and simplified color scheme
How can we either hide or grey out the upload icon in the Edit window? We have uploading disabled
Can the user avatars on the website and the content page of the post be hidden?
Removing category descriptions in main page, but retain them in individual category pages?
How to disable title changes for all users on Discourse?
Beginner's guide to using Discourse Themes
Trying to re-align an element of a theme and just wondering what it's called
Selected Quote Background Color
Differentiate contents from the topic list rows using different colors
Adjusting default composer height
Removing options from user activity action list
Understanding and managing post notices
Understanding and managing post notices
Is there a way to remove the pop-ups when making a new topic?
Looking for the perfect theme
Default category heading not hidden when category banner is used
Search section like on Reddit?

Could this be made a wiki? The info under the heading Where Do I Add My CSS? needs updating, because there is no more Edit CSS/HTML button if you installed an existing theme — which is likely now if someone chose a theme through the newer Setup Wizard. Now we just use theme components that will be added to existing themes.

https://meta.discourse.org/t/make-css-changes-on-your-site/168101#where-do-i-add-my-css-5

I can update it once it’s made into a wiki.

10개의 좋아요

Ok this is done now :+1:

5개의 좋아요

Thank you. Thanks to this part, I finally got the answer I wanted.

I needed a Discourse instance for various personal uses, so I installed it on a VPS a few days ago.

The text color in read topic was displaying too faintly, so I was searching for a solution. I had no idea there was a custom CSS setting under the ‘Component’ section.

I achieved the desired result with the following CSS. If anyone knows a better method, please leave a comment.

.topic-list-item.visited a.title:not(.badge-notification),
.latest-topic-list-item.visited a.title:not(.badge-notification),
.category-topic-link.visited a.title:not(.badge-notification),
{
  color: #000000;
}

1개의 좋아요