Making custom CSS changes on your site

:bookmark: Questa guida spiega come apportare modifiche CSS al tuo sito Discourse, inclusa un’introduzione al CSS, dove aggiungere il CSS in Discourse e come trovare i selettori corretti utilizzando gli strumenti di ispezione del browser.

:person_raising_hand: Livello utente richiesto: Amministratore

Riepilogo

Questa guida copre:

  1. Una breve introduzione al CSS e ai concetti chiave
  2. Come aggiungere CSS al tuo sito Discourse utilizzando i componenti del tema
  3. Utilizzo degli strumenti di ispezione del browser per trovare i selettori CSS corretti

Comprensione delle basi del CSS

CSS sta per Cascading Style Sheets. Ecco tre concetti chiave da comprendere:

  1. Struttura: una regola CSS è composta da un selettore, una proprietà e un valore.
p {
  color: red;
}
  • Selettore: p (prende di mira tutti i tag HTML <p>)
  • Proprietà: color
  • Valore: red

  1. Cascade: l’ultima regola applicata ha la precedenza. Ad esempio:
p {
  color: red;
}
p {
  color: green;
}

I paragrafi saranno verdi perché è l’ultima regola applicata.

  1. Specificità: le regole più specifiche sovrascrivono quelle meno specifiche. Ad esempio:
div p {
  color: green;
}
p {
  color: red;
}

I paragrafi all’interno dei div rimarranno verdi perché div p è più specifico di p.

Aggiungere CSS al tuo sito Discourse

Per aggiungere CSS al tuo sito Discourse:

  1. Vai su Aspetto > Temi e componenti dalla barra laterale o segui questo URL per il tuo sito: https://yoursite.com/admin/customize/components

  2. Fai clic su Installa e :heavy_plus_sign: Crea nuovo rispettivamente.

  3. Dai un nome al tuo componente del tema e fai clic su Crea

  4. Scegli a quali temi applicare il componente

  5. Fai clic su Modifica codice

  6. Aggiungi il tuo CSS alla scheda CSS

  7. Fai clic su “Salva” per applicare le modifiche.

:warning: Se hai più temi selezionabili dall’utente, assicurati di aggiungere i tuoi componenti del tema a tutti i temi pertinenti.

Trovare i selettori CSS corretti

Utilizza gli strumenti di ispezione del browser per trovare i selettori CSS corretti:

  1. Fai clic con il pulsante destro del mouse sull’elemento che desideri modificare.

  2. Seleziona “Ispeziona” dal menu contestuale.

  3. Nel pannello degli strumenti per sviluppatori, individua i selettori degli elementi.

  4. Fai clic sui rispettivi selettori e aggiungi la tua regola CSS.

  5. Copia la regola, incollala nella sezione CSS del tuo componente del tema e rimuovi le altre regole.

Per selettori più specifici, potrebbe essere necessario copiare il selettore utilizzato negli stili esistenti di Discourse e modificarlo nel tuo componente del tema.

Ecco un video che dimostra i passaggi precedenti:

:information_source: Se le tue modifiche non vengono applicate, verifica che:

  • Il componente del tema sia abilitato sui tuoi temi.
  • La tua regola CSS sia sufficientemente specifica da sovrascrivere gli stili esistenti.

Risorse aggiuntive

39 Mi Piace
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

Potrebbe essere reso un wiki? Le informazioni sotto l’intestazione Dove aggiungo il mio CSS? necessitano di un aggiornamento, perché non esiste più il pulsante Modifica CSS/HTML se hai installato un tema esistente — il che è probabile ora se qualcuno ha scelto un tema tramite il più recente Setup Wizard. Ora utilizziamo solo componenti tematici che verranno aggiunti ai temi esistenti.

Posso aggiornarlo una volta che sarà reso un wiki.

10 Mi Piace

Ok, questo è fatto :+1:

5 Mi Piace