Making custom CSS changes on your site

:bookmark: Esta guía explica cómo realizar cambios en CSS en tu sitio de Discourse, incluyendo una introducción a CSS, dónde agregar CSS en Discourse y cómo encontrar los selectores correctos usando herramientas de inspección del navegador.

:person_raising_hand: Nivel de usuario requerido: Administrador

Resumen

Esta guía cubre:

  1. Una breve introducción a CSS y conceptos clave
  2. Cómo agregar CSS a tu sitio de Discourse usando componentes de temas
  3. Uso de herramientas de inspección del navegador para encontrar los selectores CSS correctos

Entendiendo los conceptos básicos de CSS

CSS significa Hojas de Estilo en Cascada (Cascading Style Sheets). Aquí hay tres conceptos clave para entender:

  1. Estructura: Una regla CSS consta de un selector, una propiedad y un valor.
p {
  color: red;
}
  • Selector: p (apunta a todas las etiquetas p de HTML)
  • Propiedad: color
  • Valor: red

  1. Cascada: La última regla aplicada tiene precedencia. Por ejemplo:
p {
  color: red;
}
p {
  color: green;
}

Los párrafos serán verdes porque es la última regla aplicada.

  1. Especificidad: Las reglas más específicas anulan a las menos específicas. Por ejemplo:
div p {
  color: green;
}
p {
  color: red;
}

Los párrafos dentro de divs seguirán siendo verdes porque div p es más específico que p.

Agregando CSS a tu sitio de Discourse

Para agregar CSS a tu sitio de Discourse:

  1. Ve a Apariencia > Temas y componentes desde la barra lateral o sigue esta URL para tu sitio: https://yoursite.com/admin/customize/components

  2. Haz clic en Instalar y :heavy_plus_sign: Crear nuevo respectivamente.

  3. Nombra tu componente de tema y haz clic en Crear

  4. Elige a qué temas aplicar el componente

  5. Haz clic en Editar código

  6. Agrega tu CSS a la pestaña CSS

  7. Haz clic en “Guardar” para aplicar tus cambios.

:warning: Si tienes varios temas seleccionables por el usuario, asegúrate de agregar tus componentes de tema a todos los temas relevantes.

Encontrando los selectores CSS correctos

Usa las herramientas de inspección del navegador para encontrar los selectores CSS correctos:

  1. Haz clic derecho en el elemento que deseas modificar.

  2. Selecciona “Inspeccionar” en el menú contextual.

  3. En el panel de herramientas de desarrollador, localiza los selectores de elementos.

  4. Haz clic en los selectores correspondientes y agrega tu regla CSS.

  5. Copia la regla, pégala en la sección CSS de tu componente de tema y elimina otras reglas.

Para selectores más específicos, puede que necesites copiar el selector utilizado en los estilos existentes de Discourse y modificarlo en tu componente de tema.

Aquí tienes un video que demuestra los pasos anteriores:

:information_source: Si tus cambios no se aplican, verifica que:

  • El componente de tema esté habilitado en tus temas.
  • Tu regla CSS sea lo suficientemente específica para anular los estilos existentes.

Recursos adicionales

39 Me gusta
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

¿Se podría convertir esto en una wiki? La información bajo el encabezado ¿Dónde agrego mi CSS? necesita actualizarse, porque ya no existe el botón Editar CSS/HTML si instalaste un tema existente —lo cual es probable ahora si alguien eligió un tema a través del asistente de configuración más reciente. Ahora solo usamos componentes de tema que se agregarán a los temas existentes.

Puedo actualizarlo una vez que se convierta en una wiki.

10 Me gusta

Ok, esto está hecho ahora :+1:

5 Me gusta