Making custom CSS changes on your site

:bookmark: Dieser Leitfaden erklärt, wie Sie CSS-Änderungen auf Ihrer Discourse-Website vornehmen können, einschließlich einer Einführung in CSS, wo Sie CSS in Discourse hinzufügen und wie Sie die richtigen Selektoren mit Browser-Inspektionstools finden.

:person_raising_hand: Erforderliches Benutzerniveau: Administrator

Zusammenfassung

Dieser Leitfaden behandelt:

  1. Eine kurze Einführung in CSS und Schlüsselkonzepte
  2. Wie Sie CSS mit Theme-Komponenten zu Ihrer Discourse-Website hinzufügen
  3. Verwendung von Browser-Inspektionstools zum Auffinden der richtigen CSS-Selektoren

Grundlagen von CSS verstehen

CSS steht für Cascading Style Sheets. Hier sind drei Schlüsselkonzepte, die Sie verstehen sollten:

  1. Struktur: Eine CSS-Regel besteht aus einem Selektor, einer Eigenschaft und einem Wert.
p {
  color: red;
}
  • Selektor: p (zielt auf alle HTML-<p>-Tags ab)
  • Eigenschaft: color
  • Wert: red

  1. Kaskade: Die zuletzt angewendete Regel hat Vorrang. Zum Beispiel:
p {
  color: red;
}
p {
  color: green;
}

Die Absätze werden grün sein, da dies die zuletzt angewendete Regel ist.

  1. Spezifität: Spezifischere Regeln überschreiben weniger spezifische Regeln. Zum Beispiel:
div p {
  color: green;
}
p {
  color: red;
}

Absätze innerhalb von Divs bleiben grün, da div p spezifischer ist als p.

CSS zu Ihrer Discourse-Website hinzufügen

Um CSS zu Ihrer Discourse-Website hinzuzufügen:

  1. Gehen Sie zu Darstellung > Themes & Komponenten in der Seitenleiste oder folgen Sie dieser URL für Ihre Website: https://yoursite.com/admin/customize/components

  2. Klicken Sie auf Installieren und :heavy_plus_sign: Neu erstellen.

  3. Benennen Sie Ihre Theme-Komponente und klicken Sie auf Erstellen

  4. Wählen Sie aus, auf welche Themes die Komponente angewendet werden soll

  5. Klicken Sie auf Code bearbeiten

  6. Fügen Sie Ihr CSS zum CSS-Tab hinzu

  7. Klicken Sie auf “Speichern”, um Ihre Änderungen anzuwenden.

:warning: Wenn Sie mehrere vom Benutzer auswählbare Themes haben, stellen Sie sicher, dass Sie Ihre Theme-Komponenten zu allen relevanten Themes hinzufügen.

Die richtigen CSS-Selektoren finden

Verwenden Sie Browser-Inspektionstools, um die richtigen CSS-Selektoren zu finden:

  1. Klicken Sie mit der rechten Maustaste auf das Element, das Sie ändern möchten.

  2. Wählen Sie im Kontextmenü “Inspizieren” aus.

  3. Suchen Sie im Bedienfeld der Entwicklertools die Elementselektoren.

  4. Klicken Sie auf die entsprechenden Selektoren und fügen Sie Ihre CSS-Regel hinzu.

  5. Kopieren Sie die Regel, fügen Sie sie in den CSS-Bereich Ihrer Theme-Komponente ein und entfernen Sie andere Regeln.

Für spezifischere Selektoren müssen Sie möglicherweise den Selektor kopieren, der in den vorhandenen Stilen von Discourse verwendet wird, und ihn in Ihrer Theme-Komponente ändern.

Hier ist ein Video, das die obigen Schritte demonstriert:

:information_source: Wenn Ihre Änderungen nicht angewendet werden, überprüfen Sie Folgendes:

  • Die Theme-Komponente ist in Ihren Themes aktiviert.
  • Ihre CSS-Regel ist spezifisch genug, um vorhandene Stile zu überschreiben.

Zusätzliche Ressourcen

39 „Gefällt mir“
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

Könnte dies zu einem Wiki gemacht werden? Die Informationen unter der Überschrift “Wo füge ich mein CSS hinzu?” müssen aktualisiert werden, da es keinen “Bearbeiten CSS/HTML”-Button mehr gibt, wenn Sie ein bestehendes Thema installiert haben – was wahrscheinlich ist, wenn jemand ein Thema über den neueren Einrichtungsassistenten gewählt hat. Jetzt verwenden wir nur noch Themenkomponenten, die zu bestehenden Themen hinzugefügt werden.

Ich kann es aktualisieren, sobald es zu einem Wiki gemacht wurde.

10 „Gefällt mir“

Ok, das ist jetzt erledigt :+1:

5 „Gefällt mir“