SlideShare a Scribd company logo
Componentization:
CSS & Angular
David Amend @
Typical Angular project
https://angular.io/guide/styleguide#overall-structural-guidelines
> ng generate component mycomponent
CREATE src/app/componentB/componentB.component.html (30 bytes)
CREATE src/app/componentB/componentB.component.spec.ts (663 bytes)
CREATE src/app/componentB/componentB.component.ts (290 bytes)
CREATE src/app/componentB/componentB.component.scss (0 bytes)
UPDATE src/app/app.module.ts (10744 bytes)
CSS
- Where?
- Reuse?
- Componentize?
CSS in angular business component
#contact-form {
.navigation-buttons {
height: 71px;
padding-top: 30px;
position: relative;
.c-FormLinkButton {
line-height: 41px;
}
> div {
display: inline-block;
vertical-align: middle;
&:last-child {
position: absolute;
right: 0;
}}}
@media only screen and
(max-width: $mobile-max-width) {
.navigation-buttons {
height: 160px;
.c-FormLinkButton {
height: 50px;
line-height: 50px;
}
.c-MobileButton--secondary {
bottom: 10px;
position: absolute;
> a > span {
display: none;
}}
.c-FormButton--next {
top: 30px;
}}}
.target-form /deep/ {
button {
background-color: #1980d0;
border: 0;
border-radius: 3px;
color: #fff;
cursor: pointer;
font-size: 14px;
font-weight: bold;
font-family: Arial, sans-serif;
height: 39px;
min-width: 156px;
padding: 0 20px;
width: 290px;
}
.cta {
margin: 15px 0 15px 0;
}
}
@media screen and
(max-width: $mobile-max-width) {
button {
font-size: 18px;
font-weight: normal;
height: 50px;
width: 100%;
}
.pq .aw-wrapper-webui-de header.aw-pagehead
.aw-pagehead-meta.aw-bg-is-complex .aw-pagehead-metanav .aw-delimiter button {
color: #FE2E2E
}
Bad CSS quality & no reuse
Agenda
1. Style isolation/WC support by Angular
2. CSS Basic Rules
3. Summary
What is your level of CSS skills?
???
???
???
???
Novice
Expert
Angulars
Emulated View Encapsulation
(no Shadow DOM)
- _nghost-c*
- host-(element)
- host-context(.theme)
- ::ng-deepNative
Emulated
None
Angulars
Emulated View Encapsulation
(no Shadow DOM)
Example: setup
@Component({
selector: 'blue-button',
template: ` <h2>Blue</h2>
<button class="blue-button">click </button>`,
styles: [`
.blue-button {
color: blue;
}
h2 { font-size: 2rem;}
`]
}) export class BlueButtonComponent { }
@Component({
selector: 'app-root',
styleUrls:['./app.component.css'],
template: ` <h2>Buttons</h2>
<button class="red-button">click</button>
<blue-button></blue-button>
`})
export class AppComponent {
...
}
Example: Compiled, ngcontent
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Buttons</h2>
<button _ngcontent-c0="" class="red-button">Button</button>
<blue-button _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Blue</h2>
<button _ngcontent-c1="" class="blue-button">click</button>
</blue-button>
</app-root>
<style>
.blue-button[_ngcontent-c1] {
color: blue;
}
h2[_ngcontent-c1] {
font-size: 2rem;
}
</style>
.blue-button {
color:blue;
}
h2 { font-size: 2rem;}
:host(.red) h2 {
color: red;
}
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Button</h2>
<blue-button class=”red” _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Button</h2>
...
</app-root>
[_nghost-c1] h2[_ngcontent-c1] {
color: red;
}
:host {
padding: 20px;
}
[_nghost-c1] {
padding: 20px;
}
@Component({
selector: 'themeable-button',
template: `
<button>Themeable Button </button>`
, styles: [`
:host-context(.red-theme) button{
background: red;
}
:host-context(.blue-theme) button {
background: blue;
}`]
}) export class ThemeableButtonComponent {}
<root-context class="blue-theme">
<childs> …
<childs>
<themeable-button></themeable-button>
<childs>
</childs>
</root-context>
.blue-theme[_nghost-c1] button[_ngcontent-c1],
.blue-theme [_nghost-c1] button[_ngcontent-c1] {
background: blue;
}
ng-deep
:host ::ng-deep h2
{
color: black;
}
[_nghost-c1] h2 {
color: black;
}
Native
<app-root _nghost-c0="">
<h2 _ngcontent-c0="">Button</h2>
<blue-button class=”red” _nghost-c1="" _ngcontent-c0="">
<h2 _ngcontent-c1="">Button</h2>
...
</app-root>
Shadow Piercing combinators
https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13348719/
https://medium.com/@andreygoncharov/edge-hates-you-attributes-d15faf162939
mike k. Oct 10, 2017
Please, increase the priority of the issue.
The thing is Angular 2+ uses attributes to apply emulated
view encapsulation.
So the application performance may slow down when scaling.
Francois R. Jan 8, 2018 MICROSOFT EDGE TEAM
FYI, some performance improvements in this scenario should start to appear in the next release of Edge as we
improved some key scenarios. We don’t want to claim this issue is fixed yet because we aren’t on par with the other
browsers in all scenarios yet, so we will keep this issue open despite the current improvements, and will report any
further improvement towards our goal in the future as we get the opportunity to work on this further.
Web Components: Acceptance & Performance
<input type="date" name="bday">
<gold-cc-cvc-input card-type="amex"></gold-cc-cvc-input>
<progress value="1" max="4"></progress>
Step 2/4
→ iFrame alternative
→ framework-independant components
→ non corporate design
<video>
http://vic.github.io/prefix-css/
.angular-cli.json
"defaults": {
"component": {
"viewEncapsulation":
"None"
}
CSS Encapsulation: When?
.btn .btn-primary
.btn-xs-block
.btn btn-secondary
.cancel-button
.btn
.loading-contact-button
Problems
→ DOM specific rendering
→ no control of your styles
→ unstructured style components
- CSS first components
- Modular & Extendable by SCSS/Less
→ OOCSS
→ BEM
→ SMACSS
OOCSS
Object Oriented CSS
https://css-tricks.com/methods-organize-css/
Keep structure and skin separate
OOCSS: Structure & Style
<a href="#" class="btn btn-primary btn-lg disabled">click</a>
<a href="#" class="login-submit-button-disabled">Yes</a>
Style Structure
.btn {
display: inline-block;
font-weight: $btn-font-weight;
text-align: center;
white-space: nowrap;
vertical-align: middle;
user-select: none;
border: $btn-border-width solid transparent;
@include button-size($btn-padding-y, $btn-padding-x, $font-size-base, $btn-line-height, $btn-border-radius);
@include transition($btn-transition);
@each $color, $value in $theme-colors {
.btn-#{$color} {
@include button-variant($value, $value);
}
}
&.disabled,
&:disabled {
opacity: $btn-disabled-opacity;
@include box-shadow(none);
}
.row {
@include make-row();
}
> .col,
> [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
+ Flex
Separate container and content
<div class=”row”>
<span class=”col-8”>Are you sure?</span>
<a href="#" class="col-4 btn btn-primary btn-lg disabled">click</a>
</div>
ContentContainer
<div>
<span style=”width:60%;”>Are you sure?</span>
<a href="#" class="login-submit-button-disabled">Yes</a>
</div>
OOCSS: Container & Content
Depth of Applicability (DOA) → parent dependencies
Specifity → Which rule is actually applied?
button {
padding: 5px;
}
.btn {
padding: 10px;
}
.btn-lg {
padding: 10px;
}
.btn-xxl {
padding: 20px;
}
https://specificity.keegan.st/
https://jonassebastianohlsson.com/specificity-graph/
https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css
https://www.hypovereinsbank.de/etc/designs/hypovereinsbank/css/public.min.css
#sidebar div > button {
padding: 10px;
}
#sidebar div > div.border button.lg {
padding: 20px;
}
BEM
Block, Element, Modifier
<button class="btn">
<div class="btn__dropdown">
<a class="btn__dropdown__li
btn--disabled"
href="#">delete</a>
</div>
</button>
.block {}
.block__element {}
.block--modifier {}
<button class="btn">
<div class="btn__dropdown">
<a class="btn__li
btn--disabled"
href="#">delete</a>
</div>
</button>
.btn {}
.btn__dropdown {}
.btn--disabled {}
SMACSS
Scalable & Modular
Architecture for CSS
SMACSS—Scalable and Modular Architecture for CSS
● vendor/
○ _bootstrap.scss
● base/
○ _functions.scss
○ _mixins.scss
○ _variables.scss
○ _base.scss
■ state
● layout/
○ _grid.scss
○ _header.scss
○ _sidebar.scss
● main.scss
● module/
○ _navigations.scss
■ main-nav
● state
■ sub-nav
■ side-nav
○ _buttons.scss
■ state
○ _forms.scss
→ Separation of Style-Components
→ Style-State-directives
→ ViewEncapsulation.None
Use case considerations of CSS architecture
- Small application
- CSS-skills vary in team
- Integrate multiple frameworks
- Static content pages
Recap
- Corporate Design required. Performance restricted.
.angular-cli.json
"defaults": {
"component": {
"viewEncapsulation":
"None"
}
- Separation of Concerns
- /src/shared/styles/grid[fonts] Style Only Components
- /src/core/functions Angular Functional Components
- /src/core/styles/button/button.scss Style Component
- /src/core/styles/button/button.direcive.ts Angular Style-Support Component
- /src/app/ Angular Business Components
- Write Clean CSS code by OOCSS, BEM, SMACSS
Any Questions?

More Related Content

KEY
Evrone.ru / BEM for RoR
Dmitry KODer
 
TXT
Convidar para page !!
Jhonny Batista
 
PDF
Make your own wp cli command in 10min
Ivelina Dimova
 
DOC
20110820 header new style
AgentiadeturismInvenio
 
TXT
Tmx9
Lukas Mickosz
 
TXT
Posts ‹ teslaecoenergy — word press php
Miroslav Miskovic
 
TXT
Codigo taller-plugins
Rocío Valdivia
 
PPTX
Custom post-framworks
Kiera Howe
 
Evrone.ru / BEM for RoR
Dmitry KODer
 
Convidar para page !!
Jhonny Batista
 
Make your own wp cli command in 10min
Ivelina Dimova
 
20110820 header new style
AgentiadeturismInvenio
 
Posts ‹ teslaecoenergy — word press php
Miroslav Miskovic
 
Codigo taller-plugins
Rocío Valdivia
 
Custom post-framworks
Kiera Howe
 

What's hot (17)

PPSX
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
PDF
Work and play with SASS & Compass
Andreas Dantz
 
PDF
Worth the hype - styled components
kathrinholzmann
 
PDF
SULTHAN's - PHP MySQL programs
SULTHAN BASHA
 
KEY
Finding a Better Way to CSS: Navigating Sass with Compass
Claudina Sarahe
 
KEY
$.Template
Dave Furfero
 
RTF
Document
Naveed Anjum
 
PDF
Shortcodes In-Depth
Micah Wood
 
PDF
Routing System In Symfony 1.2
Alex Demchenko
 
PDF
Profit statement 00
Sandro Suzart
 
DOC
Teddy Bear Blue
angeliclv
 
PDF
12121212
Etietop Demas
 
PDF
Imageslider
Rajendra Kandel
 
PPTX
WordPress overloading Gravityforms using hooks, filters and extending classes
Paul Bearne
 
PDF
RubyBarCamp “Полезные gems и plugins”
apostlion
 
TXT
Date difference[1]
shafiullas
 
PPTX
Drawing images
MfahamedaThabaseem
 
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
Work and play with SASS & Compass
Andreas Dantz
 
Worth the hype - styled components
kathrinholzmann
 
SULTHAN's - PHP MySQL programs
SULTHAN BASHA
 
Finding a Better Way to CSS: Navigating Sass with Compass
Claudina Sarahe
 
$.Template
Dave Furfero
 
Document
Naveed Anjum
 
Shortcodes In-Depth
Micah Wood
 
Routing System In Symfony 1.2
Alex Demchenko
 
Profit statement 00
Sandro Suzart
 
Teddy Bear Blue
angeliclv
 
12121212
Etietop Demas
 
Imageslider
Rajendra Kandel
 
WordPress overloading Gravityforms using hooks, filters and extending classes
Paul Bearne
 
RubyBarCamp “Полезные gems и plugins”
apostlion
 
Date difference[1]
shafiullas
 
Drawing images
MfahamedaThabaseem
 
Ad

Similar to Componentization css angular (20)

PDF
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Codemotion
 
PDF
Intro to CSS
Michelle Ames
 
PDF
Polymer 1.0
Cyril Balit
 
PDF
Web components with Angular
Ana Cidre
 
PDF
Start your app the better way with Styled System
Hsin-Hao Tang
 
PDF
CSS in React - Will Change Transform
Joe Seifi
 
DOC
Resume
maddineni03
 
DOC
Resume
maddineni03
 
DOC
Resume
maddineni03
 
DOCX
Webtech File.docx
gambleryeager
 
PDF
The road to &lt;> styled-components: CSS in component-based systems by Max S...
React London 2017
 
PDF
[ WrocLoveRb 2012] user perspective testing using ruby
Mikstura.IT Foundation | Web & Mobile Community
 
DOCX
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
gilpinleeanna
 
DOCX
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
faithxdunce63732
 
PDF
Responsive Web Design e a Ubiquidade da Web
Eduardo Shiota Yasuda
 
PDF
LessCSS Presentation @ April 2015 GTALUG Meeting
Myles Braithwaite
 
PDF
Presentation html5 css3 by thibaut
Thibaut Baillet
 
PDF
Rapid Prototyping
Even Wu
 
PDF
Sass Essentials
romiguelangel
 
PDF
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Codemotion
 
Intro to CSS
Michelle Ames
 
Polymer 1.0
Cyril Balit
 
Web components with Angular
Ana Cidre
 
Start your app the better way with Styled System
Hsin-Hao Tang
 
CSS in React - Will Change Transform
Joe Seifi
 
Resume
maddineni03
 
Resume
maddineni03
 
Resume
maddineni03
 
Webtech File.docx
gambleryeager
 
The road to &lt;> styled-components: CSS in component-based systems by Max S...
React London 2017
 
[ WrocLoveRb 2012] user perspective testing using ruby
Mikstura.IT Foundation | Web & Mobile Community
 
My discussion Student A A8 - Cross-Site Request Forgery (CSR.docx
gilpinleeanna
 
cssblocks.css.b_page{ width 930px; margin 0 auto; position.docx
faithxdunce63732
 
Responsive Web Design e a Ubiquidade da Web
Eduardo Shiota Yasuda
 
LessCSS Presentation @ April 2015 GTALUG Meeting
Myles Braithwaite
 
Presentation html5 css3 by thibaut
Thibaut Baillet
 
Rapid Prototyping
Even Wu
 
Sass Essentials
romiguelangel
 
Prototyping w/HTML5 and CSS3
Todd Zaki Warfel
 
Ad

More from David Amend (14)

PDF
Angular 2 : learn TypeScript already with Angular 1
David Amend
 
PDF
Performance monitoring measurement angualrjs single page apps with phantomas
David Amend
 
PDF
Angularjs practical project experiences with javascript development in a bank
David Amend
 
PDF
Story about module management with angular.js
David Amend
 
PDF
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 
PDF
Reasons to migrate to modern web development with JavaScript
David Amend
 
PDF
Thin Server Architecture SPA, 5 years old presentation
David Amend
 
PDF
Javascript & Angular .js for the enterprise, lessons learned, typescript scal...
David Amend
 
PDF
Grunt Advanced Vol 2, Plugins Text I/O with fun
David Amend
 
PDF
Client Vs. Server Rendering
David Amend
 
PDF
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
David Amend
 
PDF
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
David Amend
 
PDF
Gwt widget frameworks_presentation
David Amend
 
PDF
Grunt.js and Yeoman, Continous Integration
David Amend
 
Angular 2 : learn TypeScript already with Angular 1
David Amend
 
Performance monitoring measurement angualrjs single page apps with phantomas
David Amend
 
Angularjs practical project experiences with javascript development in a bank
David Amend
 
Story about module management with angular.js
David Amend
 
Multi modularized project setup with gulp, typescript and angular.js
David Amend
 
Reasons to migrate to modern web development with JavaScript
David Amend
 
Thin Server Architecture SPA, 5 years old presentation
David Amend
 
Javascript & Angular .js for the enterprise, lessons learned, typescript scal...
David Amend
 
Grunt Advanced Vol 2, Plugins Text I/O with fun
David Amend
 
Client Vs. Server Rendering
David Amend
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
David Amend
 
Grunt js for the Enterprise Vol.1: Frontend Performance with Phantomas
David Amend
 
Gwt widget frameworks_presentation
David Amend
 
Grunt.js and Yeoman, Continous Integration
David Amend
 

Recently uploaded (20)

PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pdf
Certivo Inc
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
DOCX
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPT
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
PPTX
TestNG for Java Testing and Automation testing
ssuser0213cb
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pdf
Certivo Inc
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
The Five Best AI Cover Tools in 2025.docx
aivoicelabofficial
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Order to Cash Lifecycle Overview R12 .ppt
nbvreddy229
 
TestNG for Java Testing and Automation testing
ssuser0213cb
 
Become an Agentblazer Champion Challenge
Dele Amefo
 

Componentization css angular

  • 2. Typical Angular project https://angular.io/guide/styleguide#overall-structural-guidelines > ng generate component mycomponent CREATE src/app/componentB/componentB.component.html (30 bytes) CREATE src/app/componentB/componentB.component.spec.ts (663 bytes) CREATE src/app/componentB/componentB.component.ts (290 bytes) CREATE src/app/componentB/componentB.component.scss (0 bytes) UPDATE src/app/app.module.ts (10744 bytes) CSS - Where? - Reuse? - Componentize?
  • 3. CSS in angular business component #contact-form { .navigation-buttons { height: 71px; padding-top: 30px; position: relative; .c-FormLinkButton { line-height: 41px; } > div { display: inline-block; vertical-align: middle; &:last-child { position: absolute; right: 0; }}} @media only screen and (max-width: $mobile-max-width) { .navigation-buttons { height: 160px; .c-FormLinkButton { height: 50px; line-height: 50px; } .c-MobileButton--secondary { bottom: 10px; position: absolute; > a > span { display: none; }} .c-FormButton--next { top: 30px; }}} .target-form /deep/ { button { background-color: #1980d0; border: 0; border-radius: 3px; color: #fff; cursor: pointer; font-size: 14px; font-weight: bold; font-family: Arial, sans-serif; height: 39px; min-width: 156px; padding: 0 20px; width: 290px; } .cta { margin: 15px 0 15px 0; } } @media screen and (max-width: $mobile-max-width) { button { font-size: 18px; font-weight: normal; height: 50px; width: 100%; }
  • 4. .pq .aw-wrapper-webui-de header.aw-pagehead .aw-pagehead-meta.aw-bg-is-complex .aw-pagehead-metanav .aw-delimiter button { color: #FE2E2E } Bad CSS quality & no reuse
  • 5. Agenda 1. Style isolation/WC support by Angular 2. CSS Basic Rules 3. Summary
  • 6. What is your level of CSS skills? ??? ??? ??? ??? Novice Expert
  • 8. - _nghost-c* - host-(element) - host-context(.theme) - ::ng-deepNative Emulated None Angulars Emulated View Encapsulation (no Shadow DOM)
  • 9. Example: setup @Component({ selector: 'blue-button', template: ` <h2>Blue</h2> <button class="blue-button">click </button>`, styles: [` .blue-button { color: blue; } h2 { font-size: 2rem;} `] }) export class BlueButtonComponent { } @Component({ selector: 'app-root', styleUrls:['./app.component.css'], template: ` <h2>Buttons</h2> <button class="red-button">click</button> <blue-button></blue-button> `}) export class AppComponent { ... }
  • 10. Example: Compiled, ngcontent <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Buttons</h2> <button _ngcontent-c0="" class="red-button">Button</button> <blue-button _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Blue</h2> <button _ngcontent-c1="" class="blue-button">click</button> </blue-button> </app-root> <style> .blue-button[_ngcontent-c1] { color: blue; } h2[_ngcontent-c1] { font-size: 2rem; } </style> .blue-button { color:blue; } h2 { font-size: 2rem;}
  • 11. :host(.red) h2 { color: red; } <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Button</h2> <blue-button class=”red” _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Button</h2> ... </app-root> [_nghost-c1] h2[_ngcontent-c1] { color: red; } :host { padding: 20px; } [_nghost-c1] { padding: 20px; }
  • 12. @Component({ selector: 'themeable-button', template: ` <button>Themeable Button </button>` , styles: [` :host-context(.red-theme) button{ background: red; } :host-context(.blue-theme) button { background: blue; }`] }) export class ThemeableButtonComponent {} <root-context class="blue-theme"> <childs> … <childs> <themeable-button></themeable-button> <childs> </childs> </root-context> .blue-theme[_nghost-c1] button[_ngcontent-c1], .blue-theme [_nghost-c1] button[_ngcontent-c1] { background: blue; }
  • 13. ng-deep :host ::ng-deep h2 { color: black; } [_nghost-c1] h2 { color: black; } Native <app-root _nghost-c0=""> <h2 _ngcontent-c0="">Button</h2> <blue-button class=”red” _nghost-c1="" _ngcontent-c0=""> <h2 _ngcontent-c1="">Button</h2> ... </app-root> Shadow Piercing combinators
  • 14. https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13348719/ https://medium.com/@andreygoncharov/edge-hates-you-attributes-d15faf162939 mike k. Oct 10, 2017 Please, increase the priority of the issue. The thing is Angular 2+ uses attributes to apply emulated view encapsulation. So the application performance may slow down when scaling. Francois R. Jan 8, 2018 MICROSOFT EDGE TEAM FYI, some performance improvements in this scenario should start to appear in the next release of Edge as we improved some key scenarios. We don’t want to claim this issue is fixed yet because we aren’t on par with the other browsers in all scenarios yet, so we will keep this issue open despite the current improvements, and will report any further improvement towards our goal in the future as we get the opportunity to work on this further.
  • 15. Web Components: Acceptance & Performance <input type="date" name="bday"> <gold-cc-cvc-input card-type="amex"></gold-cc-cvc-input> <progress value="1" max="4"></progress> Step 2/4
  • 16. → iFrame alternative → framework-independant components → non corporate design <video> http://vic.github.io/prefix-css/ .angular-cli.json "defaults": { "component": { "viewEncapsulation": "None" } CSS Encapsulation: When? .btn .btn-primary .btn-xs-block .btn btn-secondary .cancel-button .btn .loading-contact-button Problems → DOM specific rendering → no control of your styles → unstructured style components
  • 17. - CSS first components - Modular & Extendable by SCSS/Less → OOCSS → BEM → SMACSS
  • 20. OOCSS: Structure & Style <a href="#" class="btn btn-primary btn-lg disabled">click</a> <a href="#" class="login-submit-button-disabled">Yes</a> Style Structure
  • 21. .btn { display: inline-block; font-weight: $btn-font-weight; text-align: center; white-space: nowrap; vertical-align: middle; user-select: none; border: $btn-border-width solid transparent; @include button-size($btn-padding-y, $btn-padding-x, $font-size-base, $btn-line-height, $btn-border-radius); @include transition($btn-transition); @each $color, $value in $theme-colors { .btn-#{$color} { @include button-variant($value, $value); } } &.disabled, &:disabled { opacity: $btn-disabled-opacity; @include box-shadow(none); } .row { @include make-row(); } > .col, > [class*="col-"] { padding-right: 0; padding-left: 0; } } + Flex
  • 22. Separate container and content <div class=”row”> <span class=”col-8”>Are you sure?</span> <a href="#" class="col-4 btn btn-primary btn-lg disabled">click</a> </div> ContentContainer <div> <span style=”width:60%;”>Are you sure?</span> <a href="#" class="login-submit-button-disabled">Yes</a> </div>
  • 23. OOCSS: Container & Content Depth of Applicability (DOA) → parent dependencies Specifity → Which rule is actually applied? button { padding: 5px; } .btn { padding: 10px; } .btn-lg { padding: 10px; } .btn-xxl { padding: 20px; } https://specificity.keegan.st/ https://jonassebastianohlsson.com/specificity-graph/ https://getbootstrap.com/docs/4.0/dist/css/bootstrap.min.css https://www.hypovereinsbank.de/etc/designs/hypovereinsbank/css/public.min.css #sidebar div > button { padding: 10px; } #sidebar div > div.border button.lg { padding: 20px; }
  • 25. <button class="btn"> <div class="btn__dropdown"> <a class="btn__dropdown__li btn--disabled" href="#">delete</a> </div> </button> .block {} .block__element {} .block--modifier {} <button class="btn"> <div class="btn__dropdown"> <a class="btn__li btn--disabled" href="#">delete</a> </div> </button> .btn {} .btn__dropdown {} .btn--disabled {}
  • 27. SMACSS—Scalable and Modular Architecture for CSS ● vendor/ ○ _bootstrap.scss ● base/ ○ _functions.scss ○ _mixins.scss ○ _variables.scss ○ _base.scss ■ state ● layout/ ○ _grid.scss ○ _header.scss ○ _sidebar.scss ● main.scss ● module/ ○ _navigations.scss ■ main-nav ● state ■ sub-nav ■ side-nav ○ _buttons.scss ■ state ○ _forms.scss
  • 28. → Separation of Style-Components → Style-State-directives → ViewEncapsulation.None
  • 29. Use case considerations of CSS architecture - Small application - CSS-skills vary in team - Integrate multiple frameworks - Static content pages
  • 30. Recap - Corporate Design required. Performance restricted. .angular-cli.json "defaults": { "component": { "viewEncapsulation": "None" } - Separation of Concerns - /src/shared/styles/grid[fonts] Style Only Components - /src/core/functions Angular Functional Components - /src/core/styles/button/button.scss Style Component - /src/core/styles/button/button.direcive.ts Angular Style-Support Component - /src/app/ Angular Business Components - Write Clean CSS code by OOCSS, BEM, SMACSS