Рубрики

purple

Compilation of green and purple

CSS variables offer similar flexibility to Sass’s variables, but without the need for compilation before being served to the browser. For example, here we’re resetting our page’s font and link styles with CSS variables.


CSS variables

Use Bootstrap’s CSS custom properties for fast and forward-looking design and development.

On this page

Bootstrap includes around two dozen CSS custom properties (variables) in its compiled CSS, with dozens more on the way for improved customization on a per-component basis. These provide easy access to commonly used values like our theme colors, breakpoints, and primary font stacks when working in your browser’s inspector, a code sandbox, or general prototyping.

All our custom properties are prefixed with bs- to avoid conflicts with third party CSS.

Root variables

Here are the variables we include (note that the :root is required) that can be accessed anywhere Bootstrap’s CSS is loaded. They’re located in our _root.scss file and included in our compiled dist files.

:root 


Component variables

We’re also beginning to make use of custom properties as local variables for various components. This way we can reduce our compiled CSS, ensure styles aren’t inherited in places like nested tables, and allow some basic restyling and extending of Bootstrap components after Sass compilation.

Have a look at our table documentation for some insight into how we’re using CSS variables.

We’re also using CSS variables across our grids—primarily for gutters—with more component usage coming in the future.


Built-in Themes #

PrimeNG ships with various free themes to choose from. The list below states all the available themes in the npm distribution with import paths. For a live preview, use the configurator at the topbar to switch themes.

 primeng/resources/themes/bootstrap4-light-blue/theme.css primeng/resources/themes/bootstrap4-light-purple/theme.css primeng/resources/themes/bootstrap4-dark-blue/theme.css primeng/resources/themes/bootstrap4-dark-purple/theme.css primeng/resources/themes/md-light-indigo/theme.css primeng/resources/themes/md-light-deeppurple/theme.css primeng/resources/themes/md-dark-indigo/theme.css primeng/resources/themes/md-dark-deeppurple/theme.css primeng/resources/themes/mdc-light-indigo/theme.css primeng/resources/themes/mdc-light-deeppurple/theme.css primeng/resources/themes/mdc-dark-indigo/theme.css primeng/resources/themes/mdc-dark-deeppurple/theme.css primeng/resources/themes/fluent-light/theme.css primeng/resources/themes/lara-light-blue/theme.css primeng/resources/themes/lara-light-indigo/theme.css primeng/resources/themes/lara-light-purple/theme.css primeng/resources/themes/lara-light-teal/theme.css primeng/resources/themes/lara-dark-blue/theme.css primeng/resources/themes/lara-dark-indigo/theme.css primeng/resources/themes/lara-dark-purple/theme.css primeng/resources/themes/lara-dark-teal/theme.css primeng/resources/themes/soho-light/theme.css primeng/resources/themes/soho-dark/theme.css primeng/resources/themes/viva-light/theme.css primeng/resources/themes/viva-dark/theme.css primeng/resources/themes/mira/theme.css primeng/resources/themes/nano/theme.css primeng/resources/themes/saga-blue/theme.css primeng/resources/themes/saga-green/theme.css primeng/resources/themes/saga-orange/theme.css primeng/resources/themes/saga-purple/theme.css primeng/resources/themes/vela-blue/theme.css primeng/resources/themes/vela-green/theme.css primeng/resources/themes/vela-orange/theme.css primeng/resources/themes/vela-purple/theme.css primeng/resources/themes/arya-blue/theme.css primeng/resources/themes/arya-green/theme.css primeng/resources/themes/arya-orange/theme.css primeng/resources/themes/arya-purple/theme.css primeng/resources/themes/nova/theme.css primeng/resources/themes/nova-alt/theme.css primeng/resources/themes/nova-accent/theme.css primeng/resources/themes/luna-amber/theme.css primeng/resources/themes/luna-blue/theme.css primeng/resources/themes/luna-green/theme.css primeng/resources/themes/luna-pink/theme.css primeng/resources/themes/rhea/theme.css 

Switch Themes #

Themes can be switched on-the-fly so that users of your app can choose their own theme. We have created a video tutorial that goes through the steps.

Themes are created with SASS using the primeng-sass-theme project available at github. This repository contains all the scss files for the components and the variables of the built-in themes so that you may customize an existing theme or create your own. The scss variables used in a theme are available at the SASS API documentation.

There are 3 alternatives to create your own theme. First option is using the Visual Editor, second one is compiling a theme with command line sass and final alternative is embedding scss files within your project to let your build environment do the compilation. In all cases, the generated theme file should be imported to your project. Here is a video tutorial that demonstrates all three options.

Visual Editor

Visual Editor is an easy way to quickly customize an existing theme without dealing with the details of the SASS API. The editor allows changing common settings like primary color for built-in themes. Once you have completed the design, click the download button to access the generated theme.css file and import it to your project as an asset. In near future, an advanced UI Designer will be available with the ability to edit all variables and components where you’ll also be able to save your themes when accessed with an account.

Theme SCSS

The theme scss is available as open source at primeng-sass-theme repository. The theme-base folder contains the theming structure of the components, themes under themes folder import the base and define the SCSS variables. The themes folder also contains all the built-in themes so you can customize their code as well.

To create your own theme, download the release matching your PrimeNG version and access the themes/mytheme folder. The sass variables to customize are available under the variables folder. The _fonts file can be used to define a custom font for your project whereas the optional _extensions file is provided to add overrides to the components designs. The theme.scss file imports the theme files along with the theme-base folder at the root to combine everything together. Next step would be compilation of the scss that can either be command line or within your project.

Compile SCSS Manually

Once your theme is ready run the following command to compile it. Note that sass command should be available in your terminal.

 sass --update themes/mytheme/theme.scss:themes/mytheme/theme.css 

Then copy and import the theme.css file in your application. For example, in Angular CLI you may place theme.css under assets folder and then import it at styles.css.

 @import 'assets/theme.css'; 

Build Time Compilation

This approach eliminates the manual compilation by delegating it to Angular CLI. Copy the theme-base folder along with themes/mytheme folder to your application where assets reside. At a suitable location like styles.scss, import the theme.scss from assets/themes/mytheme. That would be it, during build time, your project will compile the sass and import the theme. Any changes to your theme will be reflected instantly.

Scoped CSS #

Theming styles the components globally, in case you require to change the style of a certain component use ::ng-deep.

Scoped Panel

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

   

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Colin Wynn
the authorColin Wynn

Leave a Reply