π Angular Declarative Control Flow & Deferrable Views
#angular #controlFlow #defer
π© > Angular 17
β Article link
#angular #controlFlow #defer
π© > Angular 17
β Article link
π₯3
π Theming for Angular Applications with CSS Variables
#angular #guide #theming
1. Install required packages
2. Define CSS variables
π Code Link
3. Create pre-defined themes
π Code Link
4. Create a theme service to operate the theme
Create a new service from the ng-cli.
π Code Link
5. Create a theme component for the theme switcher
Create a new component from the ng-cli.
π Code Link
π Code Link
π Code Link
β Article link
#angular #guide #theming
1. Install required packages
Install the font-awesome/angular-fontawesome package for creating the theme switcher later.
npm install --save @font-awesome/angular-fontwaesome
2. Define CSS variables
First, we have to define colors as CSS variables in the styles.scss. The properties defined in the :root section could be referred to globally.
:root represents the <html> element and is identical to the selector html .
3. Create pre-defined themes
Create a new TypeScript file.
β Define required theme types (line 1 ~ line 4)
β Define required themes in the JSON format (line11 ~ line 35)
4. Create a theme service to operate the theme
Create a new service from the ng-cli.
ng g s theme
Update the service.
β Expose the method to retrieve the theme type from memory and localStorage (line 20 ~ line 23)
β Expose the method to set the theme type to memory and localStorage (line 42 ~ line 47)
The key is document.documentElement(line 55). It stands for the root DOM. In setCurrentTheme() , we set the new value for the corresponding theme.
5. Create a theme component for the theme switcher
Create a new component from the ng-cli.
ng g c theme
Update the theme.component.ts.
β In ngOnInit() phase, we set the corresponding icon for the theme type retrieved from the service (line 23 ~ line 26)
β When the user toggles, we set the icon for the next theme type retrieved from the service (line 28 ~ line 32)
Update the theme.component.html to place the icon.
Update the theme.component.scss to switch the theme of the icon.
The theme switcher will look like the following images.
β Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
π4
π 2/2 One-Liners Every Dev Needs to Know
#css
11. Automatic PDF Indicator
12. Counting with CSS
13. Grayscale Image Hover
14. Perfect Circles
15. Blend Backgrounds
16. Gradient Text
-webkit-background-clip: text leverages the power of CSS gradients and clips it to the text itself, making the text transparent and letting the gradient show through as its color.
17. First Line Emphasis
18. Dynamic Sibling Influence
19. Empty Element
20. Responsive Styling based on Orientation
β Article link
#css
11. Automatic PDF Indicator
Automatically appends β(PDF)β after links that point to PDF files, making it clear to users what type of file theyβre about to download.
a[href$=".pdf"][download]::after { content: " (PDF)" }12. Counting with CSS
The below piece of code creates a custom counter for list items, transforming them into a uniquely styled numbered list. This snippet uses the CSS counters to increment the list item number and display it before the item content:
.list { counter-reset: list-counter }
.item { counter-increment: list-counter }
.item::before { content: counter(list-counter) ". " }13. Grayscale Image Hover
This piece of CSS applies a grayscale filter to images on hover, creating an elegant visual effect that reverts to full colour when the mouse is moved away.
img:hover { filter: grayscale(100%) }14. Perfect Circles
With this one-liner, you can easily transform any element into a perfect circle.
.circle { clip-path: circle(50%) }15. Blend Backgrounds
Mix the elementβs background image with its background colour using the multiply blend mode, creating a rich, layered visual effect.
.blend-background { background-blend-mode: multiply }16. Gradient Text
-webkit-background-clip: text leverages the power of CSS gradients and clips it to the text itself, making the text transparent and letting the gradient show through as its color.
.gradient-text {
background: linear-gradient(to top, red 0%, blue 100%);
color: transparent;
-webkit-background-clip: text;
}17. First Line Emphasis
The ::first-line pseudo-element makes the first line of your paragraph stand out by making it bold and changing its colour.
p::first-line {
font-weight: bold;
color: #333;
}18. Dynamic Sibling Influence
This CSS one-liner changes the style of a target element when you hover over its sibling.
.sibling:hover ~ .target { color: #007bff }
.sibling:hover + .target { color: #007bff }19. Empty Element
This CSS trick automatically hides any element that has no content.
.element:empty { display: none }20. Responsive Styling based on Orientation
Itβs perfect for ensuring your design looks great in both portrait and landscape modes, especially on mobile devices where users might frequently change orientation.
@media (orientation: landscape) {
body {
background-color: #333
}
}β Article link
π3β€1
π2