Making custom CSS changes on your site

:bookmark: Este guia explica como fazer alterações de CSS em seu site Discourse, incluindo uma introdução ao CSS, onde adicionar CSS no Discourse e como encontrar os seletores corretos usando ferramentas de inspeção do navegador.

:person_raising_hand: Nível de usuário necessário: Administrador

Resumo

Este guia abrange:

  1. Uma breve introdução ao CSS e conceitos-chave
  2. Como adicionar CSS ao seu site Discourse usando componentes de tema
  3. Usando ferramentas de inspeção do navegador para encontrar os seletores CSS corretos

Entendendo os conceitos básicos de CSS

CSS significa Cascading Style Sheets (Folhas de Estilo em Cascata). Aqui estão três conceitos-chave para entender:

  1. Estrutura: Uma regra CSS consiste em um seletor, propriedade e valor.
p {
  color: red;
}
  • Seletor: p (seleciona todas as tags p HTML)
  • Propriedade: color
  • Valor: red

  1. Cascade (Cascata): A última regra aplicada tem precedência. Por exemplo:
p {
  color: red;
}
p {
  color: green;
}

Os parágrafos ficarão verdes porque é a última regra aplicada.

  1. Especificidade: Regras mais específicas substituem as menos específicas. Por exemplo:
div p {
  color: green;
}
p {
  color: red;
}

Os parágrafos dentro de divs permanecerão verdes porque div p é mais específico que p.

Adicionando CSS ao seu site Discourse

Para adicionar CSS ao seu site Discourse:

  1. Vá para Aparência > Temas e componentes na barra lateral ou siga este URL para o seu site: https://yoursite.com/admin/customize/components

  2. Clique em Instalar e :heavy_plus_sign: Criar Novo, respectivamente.

  3. Nomeie seu componente de tema e clique em Criar

  4. Escolha em quais temas aplicar o componente

  5. Clique em Editar Código

  6. Adicione seu CSS na aba CSS

  7. Clique em “Salvar” para aplicar suas alterações.

:warning: Se você tiver vários temas selecionáveis pelo usuário, certifique-se de adicionar seus componentes de tema a todos os temas relevantes.

Encontrando os seletores CSS corretos

Use as ferramentas de inspeção do navegador para encontrar os seletores CSS corretos:

  1. Clique com o botão direito no elemento que você deseja modificar.

  2. Selecione “Inspecionar” no menu de contexto.

  3. No painel de ferramentas do desenvolvedor, localize os seletores de elementos.

  4. Clique nos seletores respectivos e adicione sua regra CSS.

  5. Copie a regra, cole-a na seção CSS do seu componente de tema e remova outras regras.

Para seletores mais específicos, pode ser necessário copiar o seletor usado nos estilos existentes do Discourse e modificá-lo em seu componente de tema.

Aqui está um vídeo demonstrando os passos acima:

:information_source: Se suas alterações não forem aplicadas, verifique se:

  • O componente de tema está ativado em seus temas.
  • Sua regra CSS é específica o suficiente para substituir os estilos existentes.

Recursos adicionais

39 curtidas
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
Notification color: light blue
Customising Login Page
How to disable all alert banners in discourse
Disable bio, location and profile picture
Prevent users from changing their Full Names
Is it possible to change vis CSS the Category Moderator shield?
Line under avatar?
Custom CSS/HTML in non-default theme (without component)
Advanced Header Search
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)
🌐 www theme
How to change search banner headline font size?
Cloudfront cdn with discourse?
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
Selected Quote Background Color
How can i disable categories on home page?
How to remove bottom bar from all topics
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?
Search Banner image cuts off on smaller screens
"Reader Mode" theme component feedback
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
Configuring the default sidebar for your users
How to use CSS for versatile-banner
Turn off the “views” on topic
CSS edits not being applied on mobile
How to make login and registration pages look like this?
Theme Identification
How to customize the composer toolbar?
Which path or file handles the custom template CSS?
Top contributors sidebar Backgound
Homepage Feature
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
How can discourse administrators turn off personal messages
How to change/remove icon on login screen?
Easy Responsive Footer
Versatile Banner
Versatile Banner
Howto add a GAP between Categories
How can I add a menu item
Can't remove topic footer buttons on iOS
Discourse Docs
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
Adding a table to your post using markdown
Search section like on Reddit?
Search section like on Reddit?
How to hide a button (SVG icon) if user is logged in?
Change the headings of preferences settings

Isso poderia ser transformado em uma wiki? As informações sob o título Onde Adiciono Meu CSS? precisam ser atualizadas, pois não há mais o botão Editar CSS/HTML se você instalou um tema existente — o que é provável agora se alguém escolheu um tema através do novo Assistente de Configuração. Agora usamos componentes de tema que serão adicionados a temas existentes.

Posso atualizá-lo assim que for transformado em uma wiki.

10 curtidas

Ok, isso foi concluído :+1:

5 curtidas