Angular πŸ‡ΊπŸ‡¦ - practical notes
1.63K subscribers
1.6K photos
1 file
532 links
Angular - practical notes

This group is for posting practical notes for Angular developers. Mostly all posts are for quick implementation https://t.me/angular_practical_notes (Commenting on posts only in ENG and UA langs here). Welcome!
Download Telegram
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ”₯1
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ“„ Defining Animation Keyframes with @keyframes

#css #keyframes

The modern CSS standard offers two solutions for creating smooth animations for DOM elements:

1. Switching
CSS property values smoothly based on user interactions with the transition property.
2. Implementing keyframes-based advanced animations using the animation property.

The second approach requires defining keyframes, so the
@keyframes at-rule. Look at the following example:


<div class="board">CSS</div>


@keyframes board-anim {
0%, 85%, 100% {
filter: blur(0px);
}
90% {
filter: blur(5px) contrast(200%);
}
}

.board {
padding: 12px 50px;
font-size: 24px;
font-weight: bold;
background-color: #ff9d00;
color: #222;
display: inline-block;
animation: board-anim 3s infinite linear;
}
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ“„ Modifying Printed Page Layouts with @page

#css #page

Sometimes, users need to print web pages on physical papers for offline use. Also, some users print web pages as PDF documents to save for future use. Some web apps offer server-based features to generate paper-friendly PDF documents, but you can also print any web page using the browser’s native printing feature.

The `page`
CSS at-rule offers a way to customize page dimensions, orientation, and margins of printed pages without affecting the visible browser viewport. For example, the following CSS snippet sets a 1-inch margin and A4 landscape size for printed pages:


@page {
size: A4 landscape;
margin: 1in;
}


This at-rule comes with `:first`, `:blank`, `:left`, and `:right` pseudo-classes to select specific pages of the printed document. Browse the official MDN documentation to learn more details about `page`.
πŸ‘2
πŸ“„ Defining Custom List Styles with @counter-style

#css #counterStyle

We often use ordered and unordered lists in HTML documents. For customizing them, standard browsers offer various inbuilt list marker types via the list-style-type CSS property. You can extend these list styles or implement custom styles from scratch with the @counter-style at-rule.


Look at the following CSS code snippet:


@counter-style emojis {
system: cyclic;
symbols: πŸ”΄ 🟠 🟒;
suffix: ' ';
}

ul li {
list-style-type: emojis;
}


Moreover, it’s possible to customize existing inbuilt list styles with this at-rule:


 @counter-style decimal-mod {
system: extends decimal;
prefix: '( ';
suffix: ' ): ';
pad: 2 '0';
}


ol li {
list-style-type: decimal-mod;
margin-bottom: 2px;
}

ol li::marker {
color: #780794;
}

The above CSS definition extends the default decimal list style by adding a prefix, suffix, and zero-padding.
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ“„ Adding Initial DOM Rendering Transitions with @starting-style

#css #startingStyle

When a DOM element gets rendered from an HTML document or JavaScript code snippet, it gets rendered without any initial transition animation. In the past, we typically implemented these initial animations with dynamically switched CSS classes via JavaScript. Nowadays, we can use CSS animations for these situations, but the initial animation concept undoubtedly belongs to the CSS transitions feature. The `starting-style` at-rule lets you set initial styles for a CSS selector, so you can build up a transition animation for the initial rendering step:

button {
padding: 12px;
border: none;
border-radius: 4px;
font-size: 16px;
background-color: #bbb;
opacity: 1;
transform: scale(1);
transition: all 1s linear;

@starting-style {
opacity: 0;
transform: scale(0.5);
}
}


The above code snippet plays a transition animation when a button element gets rendered on the viewport. This transition works even though you dynamically create a new element with JavaScript.
πŸ‘2
πŸ“„Defining Scoped CSS with @scope

#css #scope

By default, the traditional CSS implementation styles web pages with a global scoping concept. Moreover, in the past, no CSS scoping feature was present with the style tag, every style tag was feasible for styling any HTML node, including the root regardless of the style tag position in the DOM tree. The HTML standard tried to support scoping with the scoped attribute, but it was deprecated before becoming a web standard. Now, the modern CSS specification introduced the `scope` at-rule for defining scoped CSS.

For example, you can create a scoped style tag for styling an HTML segment as follows:


<div>
<style>
@scope {
:scope {
background-color: #ddd;
padding: 12px;
}
h3 {
padding: 0 0 6px 0;
margin: 0;
border-bottom: solid 2px #eb7e3b;
}
}
</style>
<h3>Lorem ipsum dolor sit amet</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>

The above style tag defines a scoped CSS content for the parent div element with @scope. Here, we targeted the scoped element using the :scope pseudo-class.
πŸ‘1
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ“„Modern Component-Oriented Responsive Design with @container

#css #container

The modern CSS specification offers container queries via the @container at-rule for this requirement.

Look at the following sample:

<div class="alert">
<h3>Lorem ipsum dolor sit amet</h3>
<button>Lorem ipsum</button>
<button>Lorem ipsum</button>
</div>


.alert {
background-color: #ddd;
padding: 12px;
resize: horizontal;
overflow: hidden;
container-type: inline-size;
}

.alert h3 {
padding: 0 0 6px 0;
margin: 0 0 12px 0;
border-bottom: solid 2px #eb7e3b;
}

.alert button {
padding: 12px;
border: none;
margin-right: 6px;
}

@container (width < 400px) {
.alert button {
width: 100%;
box-sizing: border-box;
}

.alert button:not(:last-child) {
margin-bottom: 10px;
}
}
πŸ‘2
πŸ“„ Handling CSS Precedence with @layer

#css #layer

In web design scenarios, developers typically use multiple CSS selectors and often have to override styles. Even though you don’t override CSS styles with multiple selectors by yourself, every CSS block you write automatically overrides styles from the user-agent stylesheet. CSS’s style overriding process happens based on the browser’s specificity algorithm that calculates a weight for CSS selectors for handling precedence. In the past, every developer tweaked their CSS overriding-related code based on the specificity algorithm since they didn’t have a way to handle CSS precedence without using confusing !important.
πŸ‘1
πŸ“„ Π‘SS becomes SCSS

#css #scss #root #nesting #is #has #container @layer

Sass has established itself as a powerful preprocessor installed locally, forming the backbone of my projects for over a decade. It enabled me to efficiently organize scalable and stable CSS packages. Even today, I still consider Sass to be an extraordinarily powerful tool. Yet, as we step into the year 2024, it’s undeniable that CSS has undergone rapid development. Features that were once unique to Sass are now natively integrated into CSS, including variables and the latest highlight: CSS Nesting.


βœ… Article link
πŸ”₯1πŸ‘1
πŸ“„ 1/2 One-Liners Every Dev Needs to Know

#css

1. Prevent Text Selection

.no-select { user-select: none }


2. Responsive Text Size
Enter the magic of clamp(): this CSS function dynamically adjusts the font size based on the viewport width, ensuring your text is always just right.


.responsive-text { font-size: clamp(1rem, 2.5vw, 2rem) }


3. Maintain Aspect Ratio
Perfect for responsive design, setting an element’s aspect ratio will scale it beautifully while keeping its width and height in a specified ratio.


.aspect-ratio { aspect-ratio: 16 / 9 }


4. Automatic Smooth Scrolling
Simply applying scroll-behavior: smooth to the <html> element makes any anchor link or navigation jumps glide gently instead of the default abrupt jump


html { scroll-behavior: smooth }


5. Scroll Snapping
This forces scrollable content to lock to a certain element, making it perfect for image galleries or a horizontally scrolling menu


.scroll-snap { scroll-snap-type: x mandatory }


6. Responsive Dark Mode
Automatically switch your website’s theme to dark mode based on the user’s system preferences with this CSS media query (the one-liner here is the media query).


@media (prefers-color-scheme: dark) {
body {
background-color: #333;
color: #fff;
}
}


7. Full-width Responsive Images
This piece of CSS makes images fully adaptable to various screen sizes.


.cover-img { object-fit: cover }


8. Disable Pointer Interactions

Use this to make an element ignore pointer events like mouse clicks, which is particularly useful for overlays or disabled buttons.


.cover-img { object-fit: cover }


9. Blurry Background or Elements
This CSS declaration adds a blur effect to any element, great for creating focus on modal windows or for artistic background effects.


.blur { filter: blur(20px) }


10. Dynamic Content from HTML Attributes
Dynamically insert content before (or after) an element based on its class name.


.dynamic-content::before { content: attr(class) }


βœ… Article link
πŸ‘5
πŸ“„ 2/2 One-Liners Every Dev Needs to Know

#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
πŸ†š CSS class naming conventions

#css #bem #smaCSS #ooCSS

βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ†š Useful CSS Properties

#css #guide

βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ†š A Scalable CSS Architecture for Modern Web Applications

#css #info #guide

The Core Challenge of Scaling CSS

As applications evolve, managing styling consistently becomes even harder. Web projects often face issues like:

β€” Inconsistent UI elements: Without a unified system, different pages or features can drift apart visually.
β€” Hard-to-maintain styles: Styling becomes scattered and unorganized, making future changes tedious and error-prone.
β€” Difficulty in updating themes or branding: Modifying a color or spacing may involve updating hundreds of individual styles.


βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘4
πŸ†š CSS New Features

#css #guide #info

This is a list of the new changes (more details below):

β€” Changes to attr() function: so it can be used with any attribute and in any CSS property (not only on content).

β€” calc-size() function: use intrinsic values such as auto or min-content in calculations.

β€” New first-valid() function to avoid issues with custom properties with invalid values.

β€” New *-mix() family of functions with a new notation for ratios.

β€” New *-progress() family of functions to calculate the progress ratio between a range or within a media or container.

β€” Randomization with new random() and random-item() functions, to return random values from a range or list (finally!)

β€” New sibling-count() and sibling-index() functions that provide integer values to operate depending on the order and size.

β€” New toggle() function for styling nested elements easily cycling over a list of values.

β€” New functional notation for arguments with comma-separated lists of values, to avoid ambiguity with the comma separating the arguments.

β€” New URL modifiers to provide more control over url() requests.

β€” Extension of the position type to allow flow-relative values.


βœ… Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘5