Last active
October 20, 2021 15:48
-
-
Save Karytonn/93dde46b048fea690efb5a0c201ef986 to your computer and use it in GitHub Desktop.
Angular: font-size and accessibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'app-header-accessibility', | |
templateUrl: './header-accessibility.component.html', | |
styleUrls: ['./header-accessibility.component.scss'] | |
}) | |
export class HeaderAccessibilityComponent implements OnInit { | |
//Default and reset font size | |
font_size = 16; | |
//Increase, decrease and set default font size | |
setFontSize(idd: string) { | |
//calc font size | |
if(idd === 'a+'){ | |
this.font_size += 1; | |
} else if(idd === 'a-') { | |
this.font_size -= 1; | |
} else { | |
this.font_size = 16; | |
} | |
//set font size | |
let htmlRoot:HTMLElement = <HTMLElement> document.getElementsByTagName("html")[0]; | |
if (htmlRoot != null) { | |
htmlRoot.style.fontSize = `${this.font_size}px`; | |
} | |
} | |
constructor() { } | |
ngOnInit(): void { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span style="font-size: 0.5rem">Tamanho equivalente a 7.5px</span> | |
<h1 style="font-size: 2rem">Tamanho equivalente a 32px</h1> | |
<p style="font-size: 1rem">Tamanho equivalente a 16px</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
font-size: 16px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li> | |
<button (click)="setFontSize('a-')">A-</button> | |
<button (click)="setFontSize('a')">A</button> | |
<button (click)="setFontSize('a+')">A+</button> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment