├── CODE-OF-CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets └── img │ └── bulb.svg └── translations ├── de-DE └── README.md ├── es-ES └── README.md ├── fr-FR └── README.md ├── gr-GR └── README.md ├── gu-IND └── README.md ├── it-IT └── README.md ├── ja-JP └── README.md ├── ko-KR └── readme.md ├── pl-PL └── README.md ├── pt-BR └── README.md ├── pt-PT └── README.md ├── ru-RU └── README.md ├── vn-VN └── README.md ├── zh-CN └── README.md └── zh-TW └── README.md /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 6 | 7 | Examples of unacceptable behavior by participants include: 8 | 9 | * The use of sexualized language or imagery 10 | * Personal attacks 11 | * Trolling or insulting/derogatory comments 12 | * Public or private harassment 13 | * Publishing other's private information, such as physical or electronic addresses, without explicit permission 14 | * Other unethical or unprofessional conduct 15 | 16 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 17 | 18 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. 19 | 20 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 21 | 22 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at mjsmithme@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. 23 | 24 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/](http://contributor-covenant.org/version/1/3/0/). -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Please note that this project is released with a [Contributor Code of Conduct](CODE-OF-CONDUCT.md). By participating in this project you agree to abide by its terms. 4 | 5 | ## Contents 6 | 7 | - [Adding to This List](#adding-to-this-list) 8 | - [Updating Your Pull Request](#updating-your-pull-request) 9 | 10 | ## Adding to This List 11 | 12 | Please ensure your pull request adheres to the following guidelines: 13 | 14 | - Search open and closed PRs to avoid duplicate suggestions. 15 | - Only submit CSS tips that you think would be useful to others. This implies each tip has enough succinct content to describe why it's useful. 16 | - Add your tip at the bottom of the [README](https://github.com/AllThingsSmitty/css-protips/blob/master/README.md) document. Add a link to your tip at the bottom of the table of contents. 17 | - Use [title-case](https://titlecaseconverter.com/). 18 | - Code formatting should follow standard [CSSLint](http://www.csslint.net) default settings, including: 19 | - Indent with two spaces 20 | - Use shorthand, e.g., `margin: 10px 10px 0.5rem;` 21 | - Use double quotes, e.g., `background: url("logo.svg");` 22 | - Use leading zeros with numberic values, e.g., `padding: 0.75rem;` 23 | - Sort properties alphabetically 24 | - **Avoid letting your code formatter format other section of the README file.** 25 | - Make sure your text editor is set to remove trailing whitespace. 26 | - Check your spelling and grammar. 27 | - The PR should have a useful title. 28 | 29 | Thank you for your suggestions! 30 | 31 | ## Updating Your Pull Request 32 | 33 | Sometimes a maintainer will ask you to edit your pull request before it's included. This is normally due to spelling errors or because your PR didn't match the above guidelines. [This write-up](https://github.com/RichardLitt/knowledge/blob/master/github/amending-a-commit-guide.md) covers the different ways you can change a pull request. 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Statement of Purpose 4 | 5 | The laws of most jurisdictions throughout the world automatically confer 6 | exclusive Copyright and Related Rights (defined below) upon the creator and 7 | subsequent owner(s) (each and all, an "owner") of an original work of 8 | authorship and/or a database (each, a "Work"). 9 | 10 | Certain owners wish to permanently relinquish those rights to a Work for the 11 | purpose of contributing to a commons of creative, cultural and scientific 12 | works ("Commons") that the public can reliably and without fear of later 13 | claims of infringement build upon, modify, incorporate in other works, reuse 14 | and redistribute as freely as possible in any form whatsoever and for any 15 | purposes, including without limitation commercial purposes. These owners may 16 | contribute to the Commons to promote the ideal of a free culture and the 17 | further production of creative, cultural and scientific works, or to gain 18 | reputation or greater distribution for their Work in part through the use and 19 | efforts of others. 20 | 21 | For these and/or other purposes and motivations, and without any expectation 22 | of additional consideration or compensation, the person associating CC0 with a 23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright 24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work 25 | and publicly distribute the Work under its terms, with knowledge of his or her 26 | Copyright and Related Rights in the Work and the meaning and intended legal 27 | effect of CC0 on those rights. 28 | 29 | 1. Copyright and Related Rights. A Work made available under CC0 may be 30 | protected by copyright and related or neighboring rights ("Copyright and 31 | Related Rights"). Copyright and Related Rights include, but are not limited 32 | to, the following: 33 | 34 | i. the right to reproduce, adapt, distribute, perform, display, communicate, 35 | and translate a Work; 36 | 37 | ii. moral rights retained by the original author(s) and/or performer(s); 38 | 39 | iii. publicity and privacy rights pertaining to a person's image or likeness 40 | depicted in a Work; 41 | 42 | iv. rights protecting against unfair competition in regards to a Work, 43 | subject to the limitations in paragraph 4(a), below; 44 | 45 | v. rights protecting the extraction, dissemination, use and reuse of data in 46 | a Work; 47 | 48 | vi. database rights (such as those arising under Directive 96/9/EC of the 49 | European Parliament and of the Council of 11 March 1996 on the legal 50 | protection of databases, and under any national implementation thereof, 51 | including any amended or successor version of such directive); and 52 | 53 | vii. other similar, equivalent or corresponding rights throughout the world 54 | based on applicable law or treaty, and any national implementations thereof. 55 | 56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, 57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and 58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright 59 | and Related Rights and associated claims and causes of action, whether now 60 | known or unknown (including existing as well as future claims and causes of 61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum 62 | duration provided by applicable law or treaty (including future time 63 | extensions), (iii) in any current or future medium and for any number of 64 | copies, and (iv) for any purpose whatsoever, including without limitation 65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes 66 | the Waiver for the benefit of each member of the public at large and to the 67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver 68 | shall not be subject to revocation, rescission, cancellation, termination, or 69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work 70 | by the public as contemplated by Affirmer's express Statement of Purpose. 71 | 72 | 3. Public License Fallback. Should any part of the Waiver for any reason be 73 | judged legally invalid or ineffective under applicable law, then the Waiver 74 | shall be preserved to the maximum extent permitted taking into account 75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver 76 | is so judged Affirmer hereby grants to each affected person a royalty-free, 77 | non transferable, non sublicensable, non exclusive, irrevocable and 78 | unconditional license to exercise Affirmer's Copyright and Related Rights in 79 | the Work (i) in all territories worldwide, (ii) for the maximum duration 80 | provided by applicable law or treaty (including future time extensions), (iii) 81 | in any current or future medium and for any number of copies, and (iv) for any 82 | purpose whatsoever, including without limitation commercial, advertising or 83 | promotional purposes (the "License"). The License shall be deemed effective as 84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the 85 | License for any reason be judged legally invalid or ineffective under 86 | applicable law, such partial invalidity or ineffectiveness shall not 87 | invalidate the remainder of the License, and in such case Affirmer hereby 88 | affirms that he or she will not (i) exercise any of his or her remaining 89 | Copyright and Related Rights in the Work or (ii) assert any associated claims 90 | and causes of action with respect to the Work, in either case contrary to 91 | Affirmer's express Statement of Purpose. 92 | 93 | 4. Limitations and Disclaimers. 94 | 95 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 96 | surrendered, licensed or otherwise affected by this document. 97 | 98 | b. Affirmer offers the Work as-is and makes no representations or warranties 99 | of any kind concerning the Work, express, implied, statutory or otherwise, 100 | including without limitation warranties of title, merchantability, fitness 101 | for a particular purpose, non infringement, or the absence of latent or 102 | other defects, accuracy, or the present or absence of errors, whether or not 103 | discoverable, all to the greatest extent permissible under applicable law. 104 | 105 | c. Affirmer disclaims responsibility for clearing rights of other persons 106 | that may apply to the Work or any use thereof, including without limitation 107 | any person's Copyright and Related Rights in the Work. Further, Affirmer 108 | disclaims responsibility for obtaining any necessary consents, permissions 109 | or other rights required for any use of the Work. 110 | 111 | d. Affirmer understands and acknowledges that Creative Commons is not a 112 | party to this document and has no duty or obligation with respect to this 113 | CC0 or use of the Work. 114 | 115 | For more information, please see 116 | -------------------------------------------------------------------------------- /assets/img/bulb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /translations/de-DE/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # CSS Profi-Tipps [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | Eine Sammlung an Tipps, um deine CSS-Fähigkeiten zu professionalisieren. 8 | 9 | > Für andere großartige Listen schaue dir [@sindresorhus](https://github.com/sindresorhus/)s kuratierte Liste von ["awesome" Listen](https://github.com/sindresorhus/awesome/) an. 10 | 11 | 12 | ## Inhaltsverzeichnis 13 | 14 | * [Profi-Tipps](#profi-tipps) 15 | * [Unterstützung](#unterstützung) 16 | * [Mitarbeitsrichtlinien](../../CONTRIBUTING.md) 17 | 18 | 19 | ## Profi-Tipps 20 | 21 | 1. [Benutze ein CSS-Reset](#benutze-ein-css-reset) 22 | 1. [Übernehme `box-sizing`](#Übernehme-box-sizing) 23 | 1. [Benutze `unset`, anstatt alle Eigenschaften zurückzusetzen](#benutze-unset-anstatt-alle-eigenschaften-zurückzusetzen) 24 | 1. [Benutze `:not()` um Rahmen an die Navigation zu setzen oder zu entfernen](#benutze-not-um-rahmen-an-die-navigation-zu-setzen-oder-zu-entfernen) 25 | 1. [Kontroller, om skrifttypen er installeret lokalt](#Kontroller-om-skrifttypen-er-installeret-lokalt) 26 | 1. [Ergänze `line-height` an `body`](#ergänze-line-height-an-body) 27 | 1. [Setze `:focus` für Form-Elemente](#setze-focus-für-form-elemente) 28 | 1. [Zentriere alles vertikal](#zentriere-alles-vertikal) 29 | 1. [Kommaseparierte Liste](#kommaseparierte-liste) 30 | 1. [Selektiere Items mit einem negativen `nth-child`](#selektiere-items-mit-einem-negativen-nth-child) 31 | 1. [Benutze SVG für Symbole](#benutze-svg-für-symbole) 32 | 1. [Benutze den "lobotomisierte Eule"-Selektor](#benutze-den-lobotomisierte-eule-selektor) 33 | 1. [Benutze `max-height` für reine CSS-Galerien](#benutze-max-height-für-reine-css-galerien) 34 | 1. [Setze Tabellenzellen auf die gleiche Weite](#setze-tabellenzellen-auf-die-gleiche-weite) 35 | 1. [Benutze Flexbox, um von Margin-Hacks wegzukommen](#benutze-flexbox-um-von-margin-hacks-wegzukommen) 36 | 1. [Benutze den Attribut-Selektor mit leeren Verlinkungen](#benutze-den-attribut-selektor-mit-leeren-verlinkungen) 37 | 1. [Gestalte "Standard"-Verlinkungen](#gestalte-standard-verlinkungen) 38 | 1. [Boxen mit zugehörigem Größenverhältnis](#boxen-mit-zugehörigem-größenverhältnis) 39 | 1. [Gestalte defekte Bilder](#gestalte-defekte-bilder) 40 | 1. [Benutze `rem` für globales Ändern der Größe; Benutze `em` für lokale Größenveränderungen](#benutze-rem-für-globales-Ändern-der-größe-benutze-em-für-lokale-größenveränderungen) 41 | 1. [Verstecke automatisch abspielende Videos, die nicht auf stumm gesetzt sind](#verstecke-automatisch-abspielende-videos-die-nicht-auf-stumm-gesetzt-sind) 42 | 1. [Benutze `:root` für flexible Schrift](#benutze-root-für-flexible-schrift) 43 | 1. [Setze `font-size` auf Formular-Elemente für eine bessere mobile Erfahrung](#setze-font-size-auf-formular-elemente-für-eine-bessere-mobile-erfahrung) 44 | 1. [Benutze `Pointer`-Events um Mausereignisse zu kontrollieren](#benutze-pointer-events-um-mausereignisse-zu-kontrollieren) 45 | 1. [Stellen Sie bei Zeilenumbrüchen, die als Abstand verwendet werden, `display: none` ein](#stellen-sie-bei-zeilenumbrüchen,-die-als-abstand-verwendet-werden-display-none-ein) 46 | 47 | 48 | ### Benutze ein CSS-Reset 49 | 50 | CSS Resets helfen dabei eine Gestaltungskonsistenz zwischen verschiedenen Browsern herzustellen, indem sie für einen sauberen Zustand zwischen den einzelnen Elementen sorgen. Du kannst eine CSS Resetsammlung wie [Normalize](http://necolas.github.io/normalize.css/), usw. benutzen, oder einen etwas einfacheren Ansatz wählen: 51 | 52 | ```css 53 | *, 54 | *::before, 55 | *::after { 56 | box-sizing: border-box; 57 | margin: 0; 58 | padding: 0; 59 | } 60 | ``` 61 | 62 | Nun werden Elemente von ihren Margins und Paddings befreit und `box-sizing` lässt dich das CSS Box-Modell handhaben. 63 | 64 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 65 | 66 | **Hinweis:** Wenn du den [Inherit `box-sizing`](#inherit-box-sizing)-Tipp im unten folgenden Punkt befolgst, kannst du dich dafür entscheiden keine `box-sizing`-Eigenschaft in dein CSS Reset aufzunehmen. 67 | 68 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 69 | 70 | 71 | ### Übernehme `box-sizing` 72 | 73 | Übernehme `box-sizing` von `html`: 74 | 75 | ```css 76 | html { 77 | box-sizing: border-box; 78 | } 79 | 80 | *, 81 | *::before, 82 | *::after { 83 | box-sizing: inherit; 84 | } 85 | ``` 86 | 87 | Dies macht es einfacher das `box-sizing` über Plugins oder andere Komponenten zu verändern. 88 | 89 | #### [Demo](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 90 | 91 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 92 | 93 | 94 | ### Benutze `unset`, anstatt alle Eigenschaften zurückzusetzen 95 | 96 | Wenn du die Eigenschaften eines Elements zurücksetzt, ist es nicht notwendig jede einzelne Eigenschaft individuell zurückzusetzen: 97 | 98 | ```css 99 | button { 100 | background: none; 101 | border: none; 102 | color: inherit; 103 | font: inherit; 104 | outline: none; 105 | padding: 0; 106 | } 107 | ``` 108 | 109 | Du kannst alle Eigenschaften eines Elements spezifizieren, indem du das `all`-Kürzel verwendest. Der Wert `unset` setzt die Eigenschaften eines Elements auf den initialen Wert zurück: 110 | 111 | ```css 112 | button { 113 | all: unset; 114 | } 115 | ``` 116 | 117 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 118 | 119 | 120 | ### Benutze `:not()` um Rahmen an die Navigation zu setzen oder zu entfernen 121 | 122 | Anstatt den Rahmen zu ergänzen… 123 | 124 | ```css 125 | /* füge den Rahmen hinzu */ 126 | .nav li { 127 | border-right: 1px solid #666; 128 | } 129 | ``` 130 | 131 | …um ihn dann beim letzten Element wieder zu entfernen… 132 | 133 | ```css 134 | /* entferne den Rahmen */ 135 | .nav li:last-child { 136 | border-right: none; 137 | } 138 | ``` 139 | 140 | …benutze die `:not()`-Pseudoklasse um nur die Elemente zu gestalten, die du willst: 141 | 142 | ```css 143 | .nav li:not(:last-child) { 144 | border-right: 1px solid #666; 145 | } 146 | ``` 147 | 148 | Sicher, du kannst `.nav li + li` verwenden, aber mit `:not()` ist die Absicht sehr klar und der CSS Selektor definiert den Rahmen auf die Weise wie ihn auch ein Mensch beschreiben würde. 149 | 150 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/LkymvO) 151 | 152 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 153 | 154 | 155 | ### Check If Font Is Installed Locally](#check-if-font-is-installed-locally) 156 | 157 | ### Kontroller, om skrifttypen er installeret lokalt 158 | 159 | Du kan kontrollere, om en skrifttype er installeret lokalt, før du henter den eksternt, hvilket også er et godt ydelsestip. 160 | 161 | ```css 162 | @font-face { 163 | font-family: "Dank Mono"; 164 | src: 165 | /* Full name */ 166 | local("Dank Mono"), 167 | /* Postscript name */ 168 | local("Dank-Mono"), 169 | /* Otherwise, download it! */ 170 | url("//...a.server/fonts/DankMono.woff"); 171 | } 172 | 173 | code { 174 | font-family: "Dank Mono", system-ui-monospace; 175 | } 176 | ``` 177 | 178 | Hat tip til Adam Argyle for at dele denne protip og [demoen](https://codepen.io/argyleink/pen/VwYJpgR). 179 | 180 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 181 | 182 | 183 | ### Ergänze `line-height` an `body` 184 | 185 | Du brauchst kein `line-height` an jedes `

`, ``, usw separat zu schreiben. Ergänze es stattdessen an `body`: 186 | 187 | ```css 188 | body { 189 | line-height: 1.5; 190 | } 191 | ``` 192 | 193 | Auf diese Weise können Textelemente dies einfach von `body` übernehmen. 194 | 195 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 196 | 197 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 198 | 199 | 200 | ### Setze `:focus` für Form-Elemente 201 | 202 | Sehende Tastaturbenutzer_innen sind auf die Fokussierung angewiesen, um unterscheiden zu können wohin Tastaturevents auf der Seite gehen. Gestalte den Fokus für Formular-Elemente klar ersichtlich und konsistenter als die voreingestellte Browserimplementation: 203 | 204 | ```css 205 | a:focus, 206 | button:focus, 207 | input:focus, 208 | select:focus, 209 | textarea:focus { 210 | box-shadow: none; 211 | outline: #000 dotted 2px; 212 | outline-offset: .05em; 213 | } 214 | ``` 215 | 216 | #### [Demo](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 217 | 218 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 219 | 220 | 221 | ### Zentriere alles vertikal 222 | 223 | Nein, das ist keine Hexerei – du kannst wirklich alle Elemente vertikal zentrieren. 224 | Das machst du mit Flexbox… 225 | 226 | ```css 227 | html, 228 | body { 229 | height: 100%; 230 | margin: 0; 231 | } 232 | 233 | body { 234 | -webkit-align-items: center; 235 | -ms-flex-align: center; 236 | align-items: center; 237 | display: -webkit-flex; 238 | display: flex; 239 | } 240 | ``` 241 | 242 | …und ebenso mit CSS Grid: 243 | 244 | ```css 245 | body { 246 | display: grid; 247 | height: 100vh; 248 | margin: 0; 249 | place-items: center center; 250 | } 251 | ``` 252 | 253 | Möchtest du etwas anderes zentrieren? Vertikal, horizontal… alles, jederzeit, überall? CSS-Tricks hat [eine schöne Ausarbeitung](https://css-tricks.com/centering-css-complete-guide/) über all dies. 254 | 255 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 256 | 257 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 258 | 259 | 260 | ### Kommaseparierte Liste 261 | 262 | Lasse Listenpunkte wie eine echte kommaseparierte Liste aussehen: 263 | 264 | ```css 265 | ul > li:not(:last-child)::after { 266 | content: ","; 267 | } 268 | ``` 269 | 270 | Benutze die `:not()`-Pseudoklasse, um nach dem letzten Listenpunkt kein Komma anzuzeigen. 271 | 272 | **Hinweis:** Dieser Tipp mag hinsichtlich der Zugänglichkeit für Bildschirmvorleseprogramme nicht ideal sein. Auch Kopieren/Einfügen von browsergeneriertem Inhalt funktioniert nicht. Handle deswegen mit Vorsicht. 273 | 274 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 275 | 276 | 277 | ### Selektiere Items mit einem negativen `nth-child` 278 | 279 | Benutze ein negatives `nth-child` im CSS um Items von 1 bis n auszuwählen. 280 | 281 | ```css 282 | li { 283 | display: none; 284 | } 285 | 286 | /* wähle die Listenpunkte 1 bis 3 und zeige sie an */ 287 | li:nth-child(-n+3) { 288 | display: block; 289 | } 290 | ``` 291 | 292 | Anderweitig, da du nun ein bisschen über die [Benutzung von `:not()`](#benutze-not-um-rahmen-an-die-navigation-zu-setzen-oder-zu-entfernen) gelernt hast, versuche folgendes: 293 | 294 | ```css 295 | /* wähle alle Listenpunkte außer die ersten 3 und zeige sie an */ 296 | li:not(:nth-child(-n+3)) { 297 | display: block; 298 | } 299 | ``` 300 | 301 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 302 | 303 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 304 | 305 | 306 | ### Benutze SVG für Symbole 307 | 308 | Es gibt keinen Grund SVG für Symbole nicht zu verwenden: 309 | 310 | ```css 311 | .logo { 312 | background: url("logo.svg"); 313 | } 314 | ``` 315 | 316 | SVG skaliert für alle verschiedenen Auflösungen sehr gut und wird von allen Browsern [zurück bis zu IE9](http://caniuse.com/#search=svg) unterstützt. Gebe deinen .png, .jpg, or .gif-jif-wasauchimmer-Dateien den Laufpass. 317 | 318 | **Hinweis:** Wenn du nur SVG-Symbole in Button-Schaltflächen für sehende Benutzer_innen verwendest und das SVG nicht geladen wird, kannst du die Zugänglichkeit wie folgt erhalten: 319 | 320 | ```css 321 | .no-svg .icon-only::after { 322 | content: attr(aria-label); 323 | } 324 | ``` 325 | 326 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 327 | 328 | 329 | ### Benutze den "lobotomisierte Eule"-Selektor 330 | 331 | Er hat zwar einen seltsamen Namen aber der Universal-Selektor (`*`) mit dem angrenzenden Geschwister-Selektor (`+`) kann starke CSS-Möglichkeiten darbieten: 332 | 333 | ```css 334 | * + * { 335 | margin-top: 1.5em; 336 | } 337 | ``` 338 | 339 | In diesem Beispiel bekommen alle Elemente im Fluss des Dokuments, die anderen Elementen folgen, `margin-top: 1.5em`. 340 | 341 | Für mehr bezüglich des "lobotomisierte Eule"-Selektors lese [Heydon Pickerings Eintrag](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) auf *A List Apart*. 342 | 343 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/grRvWq) 344 | 345 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 346 | 347 | 348 | ### Benutze `max-height` für reine CSS-Galerien 349 | 350 | Implementiere reine CSS Galerien über `max-height` in Verbindung mit `overflow: hidden`: 351 | 352 | ```css 353 | .slider { 354 | max-height: 200px; 355 | overflow-y: hidden; 356 | width: 300px; 357 | } 358 | 359 | .slider:hover { 360 | max-height: 600px; 361 | overflow-y: scroll; 362 | } 363 | ``` 364 | 365 | Das Element dehnt sich beim Überfahren zum Wert von `max-height` aus und die Galerie wird als das Ergebnis des Overflows dargestellt. 366 | 367 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 368 | 369 | 370 | ### Setze Tabellenzellen auf die gleiche Weite 371 | 372 | Tabellen können ein ganz schönes Problem sein. Versuche `table-layout: fixed`, um die Tabellenzellen auf die gleiche Größe zu setzen: 373 | 374 | ```css 375 | .calendar { 376 | table-layout: fixed; 377 | } 378 | ``` 379 | 380 | Schmerzfreie Tabellen-Layouts. 381 | 382 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALALm) 383 | 384 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 385 | 386 | 387 | ### Benutze Flexbox, um von Margin-Hacks wegzukommen 388 | 389 | Wenn du mit Spaltenabständen arbeitest, kannst du dich von `nth-`, `first-` und `last-child`-Hacks verabschieden, indem du die Flexbox-Eigenschaft `space-between` verwendest: 390 | 391 | ```css 392 | .list { 393 | display: flex; 394 | justify-content: space-between; 395 | } 396 | 397 | .list .person { 398 | flex-basis: 23%; 399 | } 400 | ``` 401 | 402 | Nun erscheinen Spaltenabstände immer gleichmäßig. 403 | 404 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 405 | 406 | 407 | ### Benutze den Attribut-Selektor mit leeren Verlinkungen 408 | 409 | Zeige Verlinkungen an, wenn das ``-Element keinen Textwert beinhaltet, das `href`-Attribut jedoch eine Verlinkung hat: 410 | 411 | ```css 412 | a[href^="http"]:empty::before { 413 | content: attr(href); 414 | } 415 | ``` 416 | 417 | Das ist äußerst praktisch. 418 | 419 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 420 | 421 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 422 | 423 | 424 | ### Gestalte "Standard"-Verlinkungen 425 | 426 | Ergänze eine Darstellung für die von Browsern voreingestellte Verlinkung: 427 | 428 | ```css 429 | a[href]:not([class]) { 430 | color: #008000; 431 | text-decoration: underline; 432 | } 433 | ``` 434 | 435 | Nun werden Verlinkungen, die über ein CMS eingesetzt wurden – welche überlicherweise kein `class`-Attribut haben – unterscheidbar sein, ohne die Kaskade im Allgemeinen zu beeinflussen. 436 | 437 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 438 | 439 | 440 | ### Boxen mit zugehörigem Größenverhältnis 441 | 442 | Um eine Box mit zugehörigem Größenverhältnis zu erstellen, brauchst du nur eine Padding-top/-bottom-Eigenschaft zu bezeichnen: 443 | 444 | ```css 445 | .container { 446 | height: 0; 447 | padding-bottom: 20%; 448 | position: relative; 449 | } 450 | 451 | .container div { 452 | border: 2px dashed #ddd; 453 | height: 100%; 454 | left: 0; 455 | position: absolute; 456 | top: 0; 457 | width: 100%; 458 | } 459 | ``` 460 | 461 | Das Anwenden eines Wertes von 20% auf die Padding-Eigenschaft erzeugt eine Box mit der gleichen Höhe in Bezug auf 20% ihrer Breite. Ungeachtet der Weite des Ansichtsfensters, wird das Kind-Div sein Seitenverhältnis beibehalten (100% / 20% = 5:1). 462 | 463 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALZvE) 464 | 465 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 466 | 467 | 468 | ### Gestalte defekte Bilder 469 | 470 | Erzeuge mit einem kleinen bisschen CSS ästhetisch ansprechendere defekte Bilder: 471 | 472 | ```css 473 | img { 474 | display: block; 475 | font-family: sans-serif; 476 | font-weight: 300; 477 | height: auto; 478 | line-height: 2; 479 | position: relative; 480 | text-align: center; 481 | width: 100%; 482 | } 483 | ``` 484 | 485 | Nun ergänze Regeln für Pseudo-Elemente, die eine Nachricht für die Benutzer_innen darstellen, sowie eine URL-Referenz des defekten Bildes: 486 | 487 | ```css 488 | img::before { 489 | content: "Entschuldige bitte, das Bild ist leider defekt :("; 490 | display: block; 491 | margin-bottom: 10px; 492 | } 493 | 494 | img::after { 495 | content: "(url: " attr(src) ")"; 496 | display: block; 497 | font-size: 12px; 498 | } 499 | ``` 500 | 501 | Lerne mehr über das Gestalten dieses Modells in [Ire Aderinokun](https://github.com/ireade/)s [ursprünglichen Beitrag](http://bitsofco.de/styling-broken-images/). 502 | 503 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 504 | 505 | 506 | ### Benutze `rem` für globales Ändern der Größe; Benutze `em` für lokale Größenveränderungen 507 | 508 | Nachdem du die grundlegende Schriftgröße (`html { font-size: 100%; }`) festgelegt hast, setze die Schriftgrößen für Textelemente auf `em`: 509 | 510 | ```css 511 | h2 { 512 | font-size: 2em; 513 | } 514 | 515 | p { 516 | font-size: 1em; 517 | } 518 | ``` 519 | 520 | Dann setze die Schriftgröße für Module auf `rem`: 521 | 522 | ```css 523 | article { 524 | font-size: 1.25rem; 525 | } 526 | 527 | aside .module { 528 | font-size: .9rem; 529 | } 530 | ``` 531 | 532 | Nun sollte jedes Modul gegliedert, einfacher zu gestalten, wartbarer und flexibler sein. 533 | 534 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 535 | 536 | 537 | ### Verstecke automatisch abspielende Videos, die nicht auf stumm gesetzt sind 538 | 539 | Das ist ein großartiger Trick für ein speziell angefertigtes Stylesheet. Vermeide es die Benutzer_innen mit den Geräuschen eines automatisch startenden Videos zu überfordern. Zeige das Video nicht, wenn die Töne nicht auf stumm geschaltet sind: 540 | 541 | ```css 542 | video[autoplay]:not([muted]) { 543 | display: none; 544 | } 545 | ``` 546 | 547 | Erneut nutzen wir die [`:not()`](#benutze-not-um-rahmen-an-die-navigation-zu-setzen-oder-zu-entfernen)-Pseudoklasse zu unserem Vorteil. 548 | 549 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 550 | 551 | 552 | ### Benutze `:root` für flexible Schrift 553 | 554 | Die Größe der Schriftart innerhalb eines _responsive_ Layouts sollte mit jedem Ansichtsfenster veränderbar sein. Du kannst die Schriftgröße basierend auf der Höhe und Weite des Fensters berechnen, indem du `:root` verwendest: 555 | 556 | ```css 557 | :root { 558 | font-size: calc(1vw + 1vh + .5vmin); 559 | } 560 | ``` 561 | 562 | Nun kannst du die `root em`-Einheit verwenden, die auf den errechneten Werten von `:root` basiert: 563 | 564 | ```css 565 | body { 566 | font: 1rem/1.6 sans-serif; 567 | } 568 | ``` 569 | 570 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 571 | 572 | [zurück zum Inhaltsverzeichnis](#inhaltsverzeichnis) 573 | 574 | 575 | ### Setze `font-size` auf Formular-Elemente für eine bessere mobile Erfahrung 576 | 577 | Um mobile Browser (iOS Safari, usw.) am Hereinzoomen in das HTML-Formular zu hindern sobald ein `` desplegable es pulsado, agrega `font-size` a la regla del selector: 592 | 593 | ```css 594 | input[type="text"], 595 | input[type="number"], 596 | select, 597 | textarea { 598 | font-size: 16px; 599 | } 600 | ``` 601 | 602 | :dancer: 603 | 604 | [volver al índice de contenidos](#tabla-de-contenido) 605 | 606 | 607 | ### Usar eventos de puntero para controlar eventos de mouse 608 | 609 | [Eventos del puntero](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events) le permiten especificar cómo el mouse interactúa con el elemento que está tocando. Para deshabilitar el evento de puntero predeterminado en un botón, por ejemplo: 610 | 611 | ```css 612 | button:disabled { 613 | opacity: .5; 614 | pointer-events: none; 615 | } 616 | ``` 617 | 618 | Es así de simple. 619 | 620 | [volver al índice de contenidos](#tabla-de-contenido) 621 | 622 | 623 | ### Establezca `display: none` en Saltos de línea utilizados como espaciado 624 | 625 | Como señaló [Harry Roberts] (https://twitter.com/csswizardry/status/1170835532584235008), esto puede ayudar a evitar que los usuarios de CMS usen saltos de línea adicionales para el espaciado: 626 | 627 | ```css 628 | br + br { 629 | display: none; 630 | } 631 | ``` 632 | 633 | [volver al índice de contenidos](#tabla-de-contenido) 634 | 635 | 636 | ## Soporte 637 | 638 | Las versiones actuales de Chrome, Firefox, Safari y Edge. 639 | -------------------------------------------------------------------------------- /translations/gr-GR/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # Εξελιγμένες συμβουλές για CSS [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | Μια συλλογή από συμβουλές για να φτάσατε τις CSS ικανότητές σας σε επαγγελματικό επίπεδο 8 | 9 | > Για άλλες ωραίες λίστες με συμβουλές δείτε την λίστα του [@sindresorhus](https://github.com/sindresorhus/) με [τέλειες λίστες](https://github.com/sindresorhus/awesome/). 10 | 11 | 12 | ## Πίνακας περιεχομένων 13 | 14 | * [Προχωρημένες Συμβουλές](#προχωρημένες-συμβουλές) 15 | * [Υποστήριξη](#υποστήριξη) 16 | * [Μεταφράσεις](../../CONTRIBUTING.md) 17 | 18 | 19 | ## Προχωρημένες Συμβουλές 20 | 21 | 1. [Χρήση μίας CSS επαναφοράς](#χρήση-μίας-CSS-επαναφοράς) 22 | 1. [Κληρονόμιση του 'box-sizing'](#κληρονόμιση-του-box-sizing) 23 | 1. [Χρήση `unset` Αντί Για Επαναφορά Όλων Των Ιδιοτήτων](#χρήση-unset-αντί-για-επαναφορά-όλων-των-ιδιοτήτων) 24 | 1. [Χρήση `:not()` για Εφαρμόσεις/Βγάλεις τα Πλαίσια κατά την Περιήγηση](#χρήση-not-για-εφαρμόσειςβγάλεις-τα-πλαίσια-κατά-την-περιήγηση) 25 | 1. [Überprüfen Sie, ob die Schriftart lokal installiert ist](#Überprüfen-sie-ob-die-schriftart-lokal-installiert-ist) 26 | 1. [Προσθήκη `line-height` στο `body`](#προσθήκη-line-height-στο-body) 27 | 1. [Θέσε `:focus` για Στοιχεία της Φόρμας](#θέσε-focus-για-στοιχεία-της-φόρμας) 28 | 1. [Κάθετο-Κεντράρισμα Όλων](#κάθετο-κεντράρισμα-όλων) 29 | 1. [Λίστες που Χωρίζονται-με-Κόμμα](#λίστες-που-χωρίζονται-με-κόμμα) 30 | 1. [Επίλογη Αντικειμένων με Χρήση Αρνητικού `nth-child`](#επίλογη-αντικειμένων-με-χρήση-αρνητικού-nth-child) 31 | 1. [Χρήση SVG για Εικονίδια](#χρήση-SVG-για-εικονίδια) 32 | 1. [Χρήση της "Λοβοτομημένης Κουκουβάγιας" για Διαλέκτη](#χρήση-της-λοβοτομημένης-κουκουβάγιας-για-διαλέκτη) 33 | 1. [Χρήση `max-height` για Αγνούς CSS Ολισθητές](#χρήση-max-height-για-αγνούς-CSS-ολισθητές) 34 | 1. [Ίσου-Πλάτους Κελία Πίνακα](#ίσου-πλάτους-κελία-πίνακα) 35 | 1. [Απέβαλλε τα Hacks των Περιθωρίων Με Flexbox](#απέβαλλε-τα-hacks-των-περιθωρίων-με-flexbox) 36 | 1. [Χρήση Επιλογής Χαρακτηριστικών με Κένα Links](#χρήση-επιλογής-χαρακτηριστικών-με-κένα-links) 37 | 1. [Δώσε στυλ στα "Προκαθορισμένα" Links](#δώσε-στυλ-στα-προκαθορισμένα-links) 38 | 1. [Εσωτερικά Κουτία Αναλογιών](#εσωτερικά-κουτία-αναλογιών) 39 | 1. [Εικόνες με Χαλασμένο Στυλ](#εικόνες-με-χαλασμένο-στυλ) 40 | 1. [Χρήση `rem` για Προσαρμογή Μεγέθους Παντού; Χρήση `em` για Τοπική Προσαρμογή Μεγέθους](#χρήση-rem-για-προσαρμογή-μεγέθους-παντού-χρήση-em-για-τοπική-προσαρμογή-μεγέθους) 41 | 1. [Απόκριψη Βίντεο με Αυτόματη Αναπαραγωγή Που Δεν Είναι σε Σίγαση](#απόκριψη-βίντεο-με-αυτόματη-αναπαραγωγή-που-δεν-είναι-σε-σίγαση) 42 | 1. [Χρήση `:root` για Ευέλικτη Γραφή](#χρήση-root-για-ευέλικτη-γραφή) 43 | 1. [Ανάθεση `font-size` στα Στοιχεία της Φόρμας για Καλύτερη Εμπειρία από Κινητό](#ανάθεση-font-size-στα-στοιχεία-της-φόρμας-για-καλύτερη-εμπειρία-από-κινητό) 44 | 1. [Χρήση Γεγονότων Δείκτη για Έλεγχο Γεγονότων του Ποντικιού](#χρήση-γεγονότων-δείκτη-για-έλεγχο-γεγονότων-του-ποντικιού) 45 | 1. [Ανάθεση `display: none` στο Τέλος των Γραμμών που Χρησιμοποιείται σαν Κενό](#ανάθεση-display-none-στο-τέλος-των-γραμμών-που-χρησιμοποιείται-σαν-κενό) 46 | 47 | 48 | ### Χρήση μίας CSS επαναφοράς 49 | 50 | Η επαναφορά του CSS βοηθάει στο στυλ αλλά καί στην σταθερότητα ανάμεσα σε διαφορετικόυς περιηγητές αναζήτησης με καθαρό πίνακα για στυλιστικά στοιχεία.Μπορείτε να χρησιμοποιήσετε μια βιβλιοθήκη CSS επαναφοράς ετσι [Normalize](http://necolas.github.io/normalize.css/), _και αλλα._, η μπορείτε να χρησιμοποιήσετε μια πιο απλοποιημένη προσέγγιση επαναφοράς: 51 | 52 | ```css 53 | *, 54 | *::before, 55 | *::after { 56 | box-sizing: border-box; 57 | margin: 0; 58 | padding: 0; 59 | } 60 | ``` 61 | 62 | Τωρα τα στοιχεία θα βγουν από τα περιθώρια και από την επένδυση, και το `box-sizing` σε αφήνει να διαχειριστείς τις διατάξεις με το CSS box model. 63 | 64 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 65 | 66 | **Σημείωση:** Αν ακολουθήσετε την [Κληρονόμιση του 'box-sizing'](#κληρονόμιση-του-box-sizing) σαν tip θα πρέπει να μην συμπεριληφθεί το 'box-sizing' στην CSS επαναφορά. 67 | 68 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 69 | 70 | 71 | ### Κληρονόμιση του 'box-sizing' 72 | 73 | Ας κληρονομιθεί το `box-sizing` από `html`: 74 | 75 | ```css 76 | html { 77 | box-sizing: border-box; 78 | } 79 | 80 | *, 81 | *::before, 82 | *::after { 83 | box-sizing: inherit; 84 | } 85 | ``` 86 | 87 | Αυτό κάνει πιο εύκολο να αλλάξει το `box-sizing` σε πρόσθετα η σε άλλα συστατικά που μοχλεύουν άλλη συμπεριφορά. 88 | 89 | #### [Démo](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 90 | 91 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 92 | 93 | 94 | ### Χρήση `unset` Αντί Για Επαναφορά Όλων Των Ιδιοτήτων 95 | 96 | Όταν επαναφέρεις τις ιδιότητες ενός στοιχείου δεν είναι απαραίτητο να επαναφέρεις τις ιδιότητες κάθε ξεχωριστού στοιχείου: 97 | 98 | ```css 99 | button { 100 | background: none; 101 | border: none; 102 | color: inherit; 103 | font: inherit; 104 | outline: none; 105 | padding: 0; 106 | } 107 | ``` 108 | 109 | Μπορείς να καθορίσεις όλες τις ιδιότητες ενός στοιχείου χρησιμοποιόντας το `all` στενογραφημένο. Αν θέσεις την τιμή σε `unset` άλλαζει τις ιδιότητες ενός στοιχείου στις αρχικές: 110 | 111 | ```css 112 | button { 113 | all: unset; 114 | } 115 | ``` 116 | 117 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 118 | 119 | 120 | ### Χρήση `:not()` για Εφαρμόσεις/Βγάλεις τα Πλαίσια κατά την Περιήγηση 121 | 122 | Αντί να θέσεις το περιθώριο... 123 | 124 | ```css 125 | /* add border */ 126 | .nav li { 127 | border-right: 1px solid #666; 128 | } 129 | ``` 130 | 131 | ...και μετά να το βγάλεις από το τελευταίο στοιχείο... 132 | 133 | ```css 134 | /* remove border */ 135 | .nav li:last-child { 136 | border-right: none; 137 | } 138 | ``` 139 | 140 | ...χρησιμοποίησε το `:not()` μια ψευδοκλάση που εφαρμόζεται μόνο στα στοιχεία που θες: 141 | 142 | ```css 143 | .nav li:not(:last-child) { 144 | border-right: 1px solid #666; 145 | } 146 | ``` 147 | 148 | Εδώ, ο CSS επιλέκτης διαβάστηκε όπως αν το περιέγραφε ένας άνθρωπος. 149 | 150 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/LkymvO) 151 | 152 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 153 | 154 | 155 | ### Überprüfen Sie, ob die Schriftart lokal installiert ist 156 | 157 | Sie können überprüfen, ob eine Schriftart lokal installiert ist, bevor Sie sie remote abrufen. Dies ist auch ein guter Leistungstipp. 158 | 159 | ```css 160 | @font-face { 161 | font-family: "Dank Mono"; 162 | src: 163 | /* Full name */ 164 | local("Dank Mono"), 165 | /* Postscript name */ 166 | local("Dank-Mono"), 167 | /* Otherwise, download it! */ 168 | url("//...a.server/fonts/DankMono.woff"); 169 | } 170 | 171 | code { 172 | font-family: "Dank Mono", system-ui-monospace; 173 | } 174 | ``` 175 | 176 | Hutspitze an Adam Argyle für das Teilen dieses Protips und dieser [Demo](https://codepen.io/argyleink/pen/VwYJpgR). 177 | 178 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 179 | 180 | 181 | ### Προσθήκη `line-height` στο `body` 182 | 183 | Δεν χρειάζεται να προσθέσεις `line-height`σε κάθε `

`, ``, _et al_. ξεχωριστά. Αντ'αυτού, πρόσθεσέ το `body`: 184 | 185 | ```css 186 | body { 187 | line-height: 1.5; 188 | } 189 | ``` 190 | 191 | Με αυτόν τον τρόπο τα στοιχεία κειμένου μπορούν να κληρονομήσουν από το `body` έυκολα. 192 | 193 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 194 | 195 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 196 | 197 | 198 | ### Θέσε `:focus` για Στοιχεία της Φόρμας 199 | 200 | Όσοι χρήστες έχουν όραση και χρησιμοποιούν πληκτρολογιο μπορούν να βασιστούν στην συγκέντωση για να αποφασίσουν 201 | που πηγαίνουν τα γεγονότα του πληκτρολογίου στην σελίδα.Κάντε τα στοίχεια συγκέντρωσης να ξεχωρίζουν και σταθερά 202 | σε μια προκαθορισμένη εφαρμογή του browser: 203 | 204 | ```css 205 | a:focus, 206 | button:focus, 207 | input:focus, 208 | select:focus, 209 | textarea:focus { 210 | box-shadow: none; 211 | outline: #000 dotted 2px; 212 | outline-offset: .05em; 213 | } 214 | ``` 215 | 216 | #### [Demo](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 217 | 218 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 219 | 220 | 221 | ### Κάθετο-Κεντράρισμα Όλων 222 | 223 | Όχι δεν είναι μαύρη μαγεία, μπορείτε όντως να κεντράρετε τα στοιχεία κάθετα. Μπορείτε να το κάνετε αυτό με flexbox... 224 | 225 | ```css 226 | html, 227 | body { 228 | height: 100%; 229 | margin: 0; 230 | } 231 | 232 | body { 233 | -webkit-align-items: center; 234 | -ms-flex-align: center; 235 | align-items: center; 236 | display: -webkit-flex; 237 | display: flex; 238 | } 239 | ``` 240 | 241 | ...και επίσης με CSS Grid: 242 | 243 | ```css 244 | body { 245 | display: grid; 246 | height: 100vh; 247 | margin: 0; 248 | place-items: center center; 249 | } 250 | ``` 251 | 252 | 253 | Θέλετε να κεντραρίσετε κάτι άλλο? Vertically, Κάθετα, οριζόντια...όπως θέλετε,όποτε θέλετε, παντού? Το CSS-Tricks έχει [a nice write-up](https://css-tricks.com/centering-css-complete-guide/) on doing all of that. 254 | 255 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 256 | 257 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 258 | 259 | 260 | ### Λίστες που Χωρίζονται-με-Κόμμα 261 | 262 | Κάντε τα αντικείμενα λίστας να φαίνονται σαν πραγματικές, χωρισμένες-με-κόμμα λίστες: 263 | 264 | ```css 265 | ul > li:not(:last-child)::after { 266 | content: ","; 267 | } 268 | ``` 269 | 270 | Χρησιμοποιείστε την `:not()` ψευδοκλάση και κανένα κόμμα δεν θα προσθεθεί στο τελευταίο αντικείμενο. 271 | 272 | **Σημείωση:** Αυτο το tip μπορεί να μην είναι ιδανικό για προσβασιμότητα, ειδικά για αυτούς που διαβάζουν απο οθόνη. Και το copy/paste από τον browser δεν δουλεύει με περιεχόμενο CSS-generated.Συνεχίστε με προσοχή. 273 | 274 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 275 | 276 | 277 | ### Επίλογη Αντικειμένων με Χρήση Αρνητικού `nth-child` 278 | 279 | Χρηιμοποιείστε το αρνητικό `nth-child` στην CSS για να επιλέξετε 1 αντικείμενο από τα n. 280 | 281 | ```css 282 | li { 283 | display: none; 284 | } 285 | 286 | /* select items 1 through 3 and display them */ 287 | li:nth-child(-n+3) { 288 | display: block; 289 | } 290 | ``` 291 | 292 | Η, αφού ήδη μάθατε να σχετικά με το [using `:not()`](#use-not-to-applyunapply-borders-on-navigation), δοκιμάστε: 293 | 294 | ```css 295 | /* select all items except the first 3 and display them */ 296 | li:not(:nth-child(-n+3)) { 297 | display: block; 298 | } 299 | ``` 300 | 301 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 302 | 303 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 304 | 305 | 306 | ### Χρήση SVG για Εικονίδια 307 | 308 | Δεν υπάρχει λόγος να μην χρησιμοποιήσετε SVG για εικονίδια: 309 | 310 | ```css 311 | .logo { 312 | background: url("logo.svg"); 313 | } 314 | ``` 315 | 316 | το SVG κλιμακώνεται ωραία με για όλους τους τύπους ανάλυσης και υποστηρίζεται από όλους του περιηγητές [back to IE9](http://caniuse.com/#search=svg). Ρίξτε τα .png, .jpg, or .gif-jif-whatev αρχεία σας. 317 | 318 | **Σημείωση:** Αν έχετε μόνο SVG εικονίδια για κουμπιά για τους χρήστες με όραση και το SVG αποτύχει να φορτωθεί, αυτό θα βοηθήσει να διατηρηθεί η προσβασιμότητα: 319 | 320 | ```css 321 | .no-svg .icon-only::after { 322 | content: attr(aria-label); 323 | } 324 | ``` 325 | 326 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 327 | 328 | 329 | ### Χρήση της "Λοβοτομημένης Κουκουβάγιας" για Διαλέκτη 330 | 331 | Μπορεί να έχει περίεργο όνομα αλλά το να χρησιμοποιείς τον καθολικό επιλέκτη (`*`) μαζί με τον παρακείμενο επιλέκτη (`+`) μπορεί να παρέχει μια ισχυρή CSS δυνατότητα: 332 | 333 | ```css 334 | * + * { 335 | margin-top: 1.5em; 336 | } 337 | ``` 338 | 339 | Σε αυτό το παράδειγμα, όλα τα στοιχεία στην ροή του αρχείου που ακολουθεί άλλα στοιχεία θα παραλάβει `margin-top: 1.5em`. 340 | 341 | Για περισσότερα πάνω στον επιλέκτη της "Λοβοτομημένης Κουκουβάγιας", διαβάστε [Heydon Pickering's post](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) πάνω στο *A List Apart*. 342 | 343 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/grRvWq) 344 | 345 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 346 | 347 | 348 | ### Χρήση `max-height` για Αγνούς CSS Ολισθητές 349 | 350 | Εφαρμογή σε CSS-only διαφάνεις με χρήση `max-height` με την υπερχύλιση κρυμμένη: 351 | 352 | ```css 353 | .slider { 354 | max-height: 200px; 355 | overflow-y: hidden; 356 | width: 300px; 357 | } 358 | 359 | .slider:hover { 360 | max-height: 600px; 361 | overflow-y: scroll; 362 | } 363 | ``` 364 | 365 | Το στοιχείο επεκτείνεται στην `max-height` τιμή σε περίπτωση αιώρησης του δέικτη από πάνω και οι η διαφάνεια προβάλλει σας αποτέλεμα υπερχύλισης. 366 | 367 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 368 | 369 | 370 | ### Ίσου-Πλάτους Κελία Πίνακα 371 | 372 | Οι πίνακες μπορεί να είναι δύσκολοι να δουλέψει κανείς. Προσπαθήστε να χρησιμοποιήσετε το `table-layout: fixed` για να διατηρίσετε τα κελία με ίδιο πλάτος: 373 | 374 | ```css 375 | .calendar { 376 | table-layout: fixed; 377 | } 378 | ``` 379 | 380 | Χωρίς-κόπο διατάξεις πινάκων. 381 | 382 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALALm) 383 | 384 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 385 | 386 | 387 | ### Απέβαλλε τα Hacks των Περιθωρίων Με Flexbox 388 | 389 | Οτάν δουλέυεις με αυλάκια στήλης μπορείς να ξεφορτοθείς το `nth-`, `first-`, και `last-child` hacks με την χρήση της ιδιότητας του flexbox `space-between` : 390 | 391 | ```css 392 | .list { 393 | display: flex; 394 | justify-content: space-between; 395 | } 396 | 397 | .list .person { 398 | flex-basis: 23%; 399 | } 400 | ``` 401 | 402 | Τώρα τα αυλάκια των στηλών φαίνονται ίσα κατανεμημένα. 403 | 404 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 405 | 406 | 407 | ### Χρήση Επιλογής Χαρακτηριστικών με Κένα Links 408 | 409 | Εμφανίστε τα links όταν το `` στοιχείο δεν έχει τιμή αλλά το `href` πεδίο εχει ενα link: 410 | 411 | ```css 412 | a[href^="http"]:empty::before { 413 | content: attr(href); 414 | } 415 | ``` 416 | 417 | Αυτό είναι πολύ βολικό. 418 | 419 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 420 | 421 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 422 | 423 | 424 | ### Δώσε στυλ στα "Προκαθορισμένα" Links 425 | 426 | Προσθέστε στυλ στα "προκαθορισμένα" links: 427 | 428 | ```css 429 | a[href]:not([class]) { 430 | color: #008000; 431 | text-decoration: underline; 432 | } 433 | ``` 434 | 435 | Τωρα τα link που εισχωρήθηκαν μεσω CMS, που συνήθς δεν έχουν πεδίο `class` , θα διαφοροποιούνται χωρίς να επηρεάζουν την γενική αλληλουχία. 436 | 437 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 438 | 439 | 440 | ### Εσωτερικά Κουτία Αναλογιών 441 | 442 | Για να φτιάξετε ενα κουτί με εσωτερική αναλογία, το μόνο που πρέπει να κάνετε είναι να εφαρμόσετε ενα top η bottom γέμισμα σε ένα div: 443 | 444 | ```css 445 | .container { 446 | height: 0; 447 | padding-bottom: 20%; 448 | position: relative; 449 | } 450 | 451 | .container div { 452 | border: 2px dashed #ddd; 453 | height: 100%; 454 | left: 0; 455 | position: absolute; 456 | top: 0; 457 | width: 100%; 458 | } 459 | ``` 460 | Το να χρησιμοποιείς το 20% του γεμίσματος κάνει το ύψος του κουτιού ίσο με 20% απο το πλάτος του. Άσχετα με το πλάτος της θέας, το παιδί div θα κρατήσει την κλίμακά του (100% / 20% = 5:1). 461 | 462 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALZvE) 463 | 464 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 465 | 466 | ### Εικόνες με Χαλασμένο Στυλ 467 | 468 | Κάντε τις χαλασμένες εικόνες πιο αισθητικά όμορφες με λίγο CSS: 469 | 470 | ```css 471 | img { 472 | display: block; 473 | font-family: sans-serif; 474 | font-weight: 300; 475 | height: auto; 476 | line-height: 2; 477 | position: relative; 478 | text-align: center; 479 | width: 100%; 480 | } 481 | ``` 482 | 483 | Τώρα προσθέστε ψευδόστοιχείων κανόνες για να εμφανίσετε ένα μύνημα χρήστη και μια αναφορά σε URL από την χαλασμένη εικόνα: 484 | 485 | ```css 486 | img::before { 487 | content: "We're sorry, the image below is broken :("; 488 | display: block; 489 | margin-bottom: 10px; 490 | } 491 | 492 | img::after { 493 | content: "(url: " attr(src) ")"; 494 | display: block; 495 | font-size: 12px; 496 | } 497 | ``` 498 | 499 | Μάθετε περισσότερα σχετικά με το στυλ για αυτό το μοτίβο στού [Ire Aderinokun](https://github.com/ireade/)'s [αρχικό ποστ](http://bitsofco.de/styling-broken-images/). 500 | 501 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 502 | 503 | 504 | ### Χρήση `rem` για Προσαρμογή Μεγέθους Παντού; Χρήση `em` για Τοπική Προσαρμογή Μεγέθους 505 | 506 | Αφού θέσετε το βασικό μέγεθος γραμματοσειράς στο root (`html { font-size: 100%; }`), θέστε το μέγεθος γραμματοσειράς για στοιχεία κειμένου σε `em`: 507 | 508 | ```css 509 | h2 { 510 | font-size: 2em; 511 | } 512 | 513 | p { 514 | font-size: 1em; 515 | } 516 | ``` 517 | 518 | Έπειτα θέστε το μέγεθος γραμματοσειράς για τις ενότητες σε `rem`: 519 | 520 | ```css 521 | article { 522 | font-size: 1.25rem; 523 | } 524 | 525 | aside .module { 526 | font-size: .9rem; 527 | } 528 | ``` 529 | 530 | Τώρα κάθε ενότητα διαχωρίζεται και είναι ευκολότερο να της δώσεις στυλ, πιο συντιρίσιμη, και ευπροσάρμοστη. 531 | 532 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 533 | 534 | 535 | ### Απόκριψη Βίντεο με Αυτόματη Αναπαραγωγή Που Δεν Είναι σε Σίγαση 536 | 537 | Αυτό είναι ένα ωραίο κόλπο για έναν στυλ συνιθισμένου χρήστη. Αποφυγή κατακλυσμού χρήστη με ήχους από ενα βίντεο το οποίο παίζει αυτόματα όταν φορτωθεί η σελίδα. Αν ο ήχος δεν είναι σε σίγαση, μήν δείχνεις το βίντεο: 538 | 539 | ```css 540 | video[autoplay]:not([muted]) { 541 | display: none; 542 | } 543 | ``` 544 | 545 | Για άλλη μία φορά,εκμεταλλευόμαστε την χρήση της [`:not()`](#χρήση-not-για-εφαρμόσεις-βγάλεις-τα-πλαίσια-κατά-την-περιήγηση) ψευδοκλάσης. 546 | 547 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 548 | 549 | 550 | ### Χρήση `:root` για Ευέλικτη Γραφή 551 | 552 | Ο τύπος της γραμματοσειράς σε μια αποκρίσιμη διαρρύθμιση θα πρέπει να είναι ικάνος να προσαρμόζεται με κάθε θέαση. Μπορείτε να υπολογίσετε το μέγεθος γραμματοσειράς με βάση το ύψος και το πλάτος της θέασης χρησιμοποιόντας το `:root`: 553 | 554 | ```css 555 | :root { 556 | font-size: calc(1vw + 1vh + .5vmin); 557 | } 558 | ``` 559 | 560 | Τώρα μπορείτε να χρησιμοποιήσετε την `root em` μονάδα βασισμένη στην τιμή που υπολογίστηκε από το `:root`: 561 | 562 | ```css 563 | body { 564 | font: 1rem/1.6 sans-serif; 565 | } 566 | ``` 567 | 568 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 569 | 570 | [πίσω στον πίνακα περιεχομένων](#πίνακας-περιεχομένων) 571 | 572 | 573 | ### Ανάθεση `font-size` στα Στοιχεία της Φόρμας για Καλύτερη Εμπειρία από Κινητό 574 | 575 | Για να αποτρέψετε τους περιηγητές των κινητών (iOS Safari, _et al_.) απο το να μεγεθύνουν στα στοιχεία της HTML φόρμας όταν ένα `` ડ્રોપ ડાઉન ટેપ થયેલ છે, ઉમેરો `font-size` to the selector rule: 578 | 579 | ```css 580 | input[type="text"], 581 | input[type="number"], 582 | select, 583 | textarea { 584 | font-size: 16px; 585 | } 586 | ``` 587 | 588 | :dancer: 589 | 590 | [સામગ્રીઓના કોષ્ટકમાં પાછા](#પ્રોપ્સ) 591 | 592 | 593 | ### માઉસ ઇવેન્ટ્સ નિયંત્રણ કરવા માટે પોઇન્ટર ઇવેન્ટ્સનો ઉપયોગ કરો 594 | 595 | [પોઇન્ટર ઇવેન્ટ્સ](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events) તમને સ્પષ્ટ કરવા માટે પરવાનગી આપે છે કે માઉસ કેવી રીતે તૃપ્તિ સાથે સંપર્ક કરે છે. બટનો પર ડિફૉલ્ટ પોઇન્ટર ઇવેન્ટને અક્ષમ કરવા માટે, ઉદાહરણ તરીકે: 596 | 597 | ```css 598 | button:disabled { 599 | opacity: .5; 600 | pointer-events: none; 601 | } 602 | ``` 603 | 604 | તે સરળ છે. 605 | 606 | [સામગ્રીઓના કોષ્ટકમાં પાછા](#પ્રોપ્સ) 607 | 608 | 609 | ### અંતર `display: none` તરીકે વપરાયેલ લાઇન બ્રેક્સ પર સેટ કરો 610 | 611 | [હેરી રોબર્ટ્સે નિર્દેશ કર્યો](https://twitter.com/csswizardry/status/1170835532584235008), આ સીએમએસ વપરાશકર્તાઓને અંતર માટે વધારાના લાઇન બ્રેકનો ઉપયોગ કરવાથી અટકાવી શકે છે: 612 | 613 | ```css 614 | br + br { 615 | display: none; 616 | } 617 | ``` 618 | 619 | [સામગ્રીઓના કોષ્ટકમાં પાછા](#પ્રોપ્સ) 620 | 621 | 622 | ## આધાર 623 | 624 | વર્તમાન આવૃત્તિઓ of Chrome, Firefox, Safari, અને Edge. 625 | 626 | [સામગ્રીઓના કોષ્ટકમાં પાછા](#પ્રોપ્સ) 627 | -------------------------------------------------------------------------------- /translations/it-IT/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # CSS suggerimenti per esperti [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | Una collezione di dritte per aiutarti a migliorare le tue capacità con CSS. 8 | 9 | > Per altre fantastiche liste di questo tipo guarda la [lista di fantastiche liste](https://github.com/sindresorhus/awesome/) curata da [@sindresorhus](https://github.com/sindresorhus/). 10 | 11 | 12 | ## Sommario 13 | 14 | * [Suggerimenti per esperti](#suggerimenti-per-esperti) 15 | * [Supporto](#supporto) 16 | * [Linee guida per contribuire](../../CONTRIBUTING.md) 17 | 18 | 19 | ## Suggerimenti per esperti 20 | 21 | 1. [Utilizzare un reset CSS](#utilizzare-un-reset-css) 22 | 1. [Eredita il `box-sizing`](#eredita-il-box-sizing) 23 | 1. [Usa `unset` invece di Reimposta tutte le proprietà](#usa-unset-invece-di-reimposta-tutte-le-proprietà) 24 | 1. [Usa `:not()` per applicare/rimuovere-i-bordi-su-elementi-di-navigazione](#usa-not-per-applicarerimuovere-i-bordi-su-elementi-di-navigazione) 25 | 1. [Controlla se il font è installato localmente](#controlla-se-il-font-è-installato-localmente) 26 | 1. [Aggiungi `line-height` al `body`](#aggiungi-line-height-al-body) 27 | 1. [Imposta `:focus` per gli elementi del modulo](#imposta-focus-per-gli-elementi-del-modulo) 28 | 1. [Centra verticalmente qualsiasi cosa](#centra-verticalmente-qualsiasi-cosa) 29 | 1. [Liste separate da virgola](#liste-separate-da-virgola) 30 | 1. [Seleziona un elemento usando gli `nth-child` negativi](#seleziona-un-elemento-usando-gli-nth-child-negativi) 31 | 1. [Usa SVG per le icone](#usa-svg-per-le-icone) 32 | 1. [Usa il selettore detto "Lobotomized Owl"](#usa-il-selettore-detto-"lobotomized-owl") 33 | 1. [Usa `max-height` per slider fatti solo con CSS](#usa-max-height-per-slider-fatti-solo-con-css) 34 | 1. [Celle di tabella con larghezza uguale](#celle-di-tabella-con-larghezza-uguale) 35 | 1. [Sbarazzati degli hack sui margini grazie a Flexbox](#sbarazzati-degli-hack-sui-margini-grazie-a-flexbox) 36 | 1. [Usa il selettore d'attributo con i link senza testo](#usa-il-selettore-d'attributo-con-i-link-senza-testo) 37 | 1. [Styling dei link di "Default"](#styling-dei-link-di-"default") 38 | 1. [Box con proporzioni intrinseche](#box-con-proporzioni-intrinseche) 39 | 1. [Styling delle immagini non scaricate](#styling-delle-immagini-non-scaricate) 40 | 1. [Usa `rem` per le grandezze globali; usa `em` per le dimensioni locali](#usa-rem-per-le-grandezze-globali;-usa-em-per-le-dimensioni-locali) 41 | 1. [Nascondi i video in riproduzione automatica che non sono silenziati](#nascondi-i-video-in-riproduzione-automatica-che-non-sono-silenziati) 42 | 1. [Usa `:root` per caratteri flessibili](#usa-:root-per-caratteri-flessibili) 43 | 1. [Imposta il `font-size` sugli elementi dei form per una migliore esperienza da mobile](#imposta-il-font-size-sugli-elementi-dei-form-per-una-migliore-esperienza-da-mobile) 44 | 1. [Utilizzare gli eventi puntatore per controllare gli eventi del mouse](#utilizzare-gli-eventi-puntatore-per-controllare-gli-eventi-del-mouse) 45 | 1. [Imposta `display: none` su Line Breaks usati come Spaziatura](#imposta-display:-none-su-line-breaks-usati-come-spaziatura) 46 | 47 | 48 | ### Utilizzare un reset CSS 49 | 50 | reset CSS aiutare a far rispettare lo stile coerenza tra diversi browser da zero per gli elementi stilistici. È possibile utilizzare libreria di reset CSS come [Normalize](http://necolas.github.io/normalize.css/), et al, oppure è possibile utilizzare un approccio più semplificato di ripristino.: 51 | 52 | ```css 53 | *, 54 | *::before, 55 | *::after { 56 | box-sizing: border-box; 57 | margin: 0; 58 | padding: 0; 59 | } 60 | ``` 61 | 62 | Ora elementi saranno spogliati di margini e padding, e `box-sizing` consente di gestire i layout con il box model CSS. 63 | 64 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 65 | 66 | **Nota:** Se si segue la punta [Eredita il `box-sizing`](#inherit-box-sizing) in basso si potrebbe optare di non includere la proprietà box-sizing nel ripristino CSS. 67 | 68 | [torna al sommario](#sommario) 69 | 70 | 71 | ### Eredita il `box-sizing` 72 | 73 | Eredita il `box-sizing` dall'elemento `html`: 74 | 75 | ```css 76 | html { 77 | box-sizing: border-box; 78 | } 79 | 80 | *, 81 | *::before, 82 | *::after { 83 | box-sizing: inherit; 84 | } 85 | ``` 86 | 87 | In questo modo diventa più facile cambiare `box-sizing` in plugin o altri componenti che ne sfruttano un altro. 88 | 89 | #### [Dimostrazione](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 90 | 91 | [torna al sommario](#sommario) 92 | 93 | 94 | ### Usa `unset` invece di Reimposta tutte le proprietà 95 | 96 | Quando si ripristinano le proprietà di un elemento, non è necessario reimpostare ogni singola proprietà: 97 | 98 | ```css 99 | button { 100 | background: none; 101 | border: none; 102 | color: inherit; 103 | font: inherit; 104 | outline: none; 105 | padding: 0; 106 | } 107 | ``` 108 | 109 | Puoi specificare tutte le proprietà di un elemento usando la stenografia `all`. L'impostazione del valore su `unset` modifica le proprietà di un elemento ai valori iniziali: 110 | 111 | ```css 112 | button { 113 | all: unset; 114 | } 115 | ``` 116 | 117 | [torna al sommario](#sommario) 118 | 119 | 120 | ### Usa `:not()` per applicare/rimuovere i bordi su elementi di navigazione 121 | 122 | Invece di impostare il bordo... 123 | 124 | ```css 125 | /* aggiunge il bordo */ 126 | .nav li { 127 | border-right: 1px solid #666; 128 | } 129 | ``` 130 | 131 | ...e poi rimuoverlo dall'ultimo elemento... 132 | 133 | ```css 134 | /* rimuove il bordo */ 135 | .nav li:last-child { 136 | border-right: none; 137 | } 138 | ``` 139 | 140 | ...usa la pseudo classe `:not()` per applicarlo solo agli elementi che vuoi: 141 | 142 | ```css 143 | .nav li:not(:last-child) { 144 | border-right: 1px solid #666; 145 | } 146 | ``` 147 | 148 | Il selettore CSS definisce il confine nel modo in cui un essere umano lo descrive. 149 | 150 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/LkymvO) 151 | 152 | [torna al sommario](#sommario) 153 | 154 | 155 | ### Controlla se il font è installato localmente 156 | 157 | Puoi verificare se un font è installato localmente prima di recuperarlo da remoto, il che è anche un buon suggerimento per le prestazioni. 158 | 159 | ```css 160 | @font-face { 161 | font-family: "Dank Mono"; 162 | src: 163 | /* Full name */ 164 | local("Dank Mono"), 165 | /* Postscript name */ 166 | local("Dank-Mono"), 167 | /* Otherwise, download it! */ 168 | url("//...a.server/fonts/DankMono.woff"); 169 | } 170 | 171 | code { 172 | font-family: "Dank Mono", system-ui-monospace; 173 | } 174 | ``` 175 | 176 | Punta del cappello ad Adam Argyle per aver condiviso questo prototipo e questa [dimostrazione](https://codepen.io/argyleink/pen/VwYJpgR). 177 | 178 | [torna al sommario](#sommario) 179 | 180 | 181 | ### Aggiungi `line-height` al `body` 182 | 183 | Non è necessario aggiungere `line-height` a ogni `

`,``, _et al_. separatamente. Invece, aggiungilo a `body`: 184 | 185 | 186 | ```css 187 | body { 188 | line-height: 1.5; 189 | } 190 | ``` 191 | 192 | In questo modo gli elementi di testo possono ereditare facilmente da `body`. 193 | 194 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 195 | 196 | [torna al sommario](#sommario) 197 | 198 | 199 | ### Imposta `:focus` per gli elementi del modulo 200 | 201 | Gli utenti con tastiera a vista si affidano alla messa a fuoco per determinare dove vanno gli eventi della tastiera nella pagina. Fai attenzione agli elementi del modulo che si distinguono e coerenti rispetto all'implementazione predefinita del browser: 202 | 203 | ```css 204 | a:focus, 205 | button:focus, 206 | input:focus, 207 | select:focus, 208 | textarea:focus { 209 | box-shadow: none; 210 | outline: #000 dotted 2px; 211 | outline-offset: .05em; 212 | } 213 | ``` 214 | 215 | #### [Dimostrazione](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 216 | 217 | [torna al sommario](#sommario) 218 | 219 | 220 | ### Centra verticalmente qualsiasi cosa 221 | 222 | No, non è magia nera. Puoi veramente centrare gli elementi verticalmente: 223 | 224 | ```css 225 | html, 226 | body { 227 | height: 100%; 228 | margin: 0; 229 | } 230 | 231 | body { 232 | -webkit-align-items: center; 233 | -ms-flex-align: center; 234 | align-items: center; 235 | display: -webkit-flex; 236 | display: flex; 237 | } 238 | ``` 239 | 240 | ...e anche con CSS Grid: 241 | 242 | ```css 243 | body { 244 | display: grid; 245 | height: 100vh; 246 | margin: 0; 247 | place-items: center center; 248 | } 249 | ``` 250 | 251 | Vuoi centrare qualcos'altro? In verticale, in orizzontale... qualsiasi cosa, in qualsiasi momento ovunque? Su CSS-Tricks trovi [un ottimo articolo](https://css-tricks.com/centering-css-complete-guide/) a riguardo. 252 | 253 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 254 | 255 | [torna al sommario](#sommario) 256 | 257 | 258 | ### Liste separate da virgola 259 | 260 | Visualizza gli elementi di una lista come fossero una vera lista con le virgole: 261 | 262 | ```css 263 | ul > li:not(:last-child)::after { 264 | content: ","; 265 | } 266 | ``` 267 | 268 | Usa la pseudo classe `:not()` in modo da non aggiungere la virgola all'ultimo elemento. 269 | 270 | **Nota bene:** può non essere l'ideale per garantire l'accessibilità, nello specifico per gli screen reader. Inoltre il copia/incolla dal browser non funziona con il contenuto generato mediante CSS. Procedi con attenzione. 271 | 272 | [torna al sommario](#sommario) 273 | 274 | 275 | ### Seleziona un elemento usando gli `nth-child` negativi 276 | 277 | Usa gli `nth-child` negativi di CSS per selezionare gli elementi da 1 a n. 278 | 279 | ```css 280 | li { 281 | display: none; 282 | } 283 | 284 | /* seleziona gli elementi da 1 a 3 e li mostra */ 285 | li:nth-child(-n+3) { 286 | display: block; 287 | } 288 | ``` 289 | 290 | Oppure, dato che hai già imparato un po' di cose circa l'[uso di `:not()`](#use-not-to-applyunapply-borders-on-navigation), prova: 291 | 292 | ```css 293 | /* selezionare tutti gli elementi tranne i primi 3 e visualizzarli */ 294 | li:not(:nth-child(-n+3)) { 295 | display: none; 296 | } 297 | ``` 298 | 299 | Beh... era abbastanza facile. 300 | 301 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 302 | 303 | [torna al sommario](#sommario) 304 | 305 | 306 | ### Usa SVG per le icone 307 | 308 | Non c'è ragione per non usare SVG per le icone: 309 | 310 | ```css 311 | .logo { 312 | background: url("logo.svg"); 313 | } 314 | ``` 315 | 316 | SVG scala molto bene a tutti i tipi di risoluzione ed è supportata in tutti i browser [fino a IE9](http://caniuse.com/#search=svg). Perciò butta i tuoi file .png, .jpg o .gif-jif-qualsiasicosa. 317 | 318 | **Nota bene:** se usi bottoni con esclusivamente grafica SVG e le icone SVG non vengono caricate, questo ti aiuterà a preservare l'accessibilità: 319 | 320 | ```css 321 | .no-svg .icon-only::after { 322 | content: attr(aria-label); 323 | } 324 | ``` 325 | 326 | [torna al sommario](#sommario) 327 | 328 | 329 | ### Usa il selettore detto "Lobotomized Owl" 330 | 331 | Sebbene il suo nome sia un po' strano, l'uso del selettore universale (`*`) insieme al selettore del fratello adiacente (`+`) può fornire una potenzialità CSS molto potente: 332 | 333 | ```css 334 | * + * { 335 | margin-top: 1.5em; 336 | } 337 | ``` 338 | 339 | In questo esempio, tutti gli elementi nel flusso del documento che seguono altri elementi riceveranno la proprietà `margin-top: 1.5em`. 340 | 341 | Per saperne di più sul selettore detto "lobotomized owl", leggi [l'articolo di Heydon Pickering](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) su *A List Apart*. 342 | 343 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/grRvWq) 344 | 345 | [torna al sommario](#sommario) 346 | 347 | 348 | ### Usa `max-height` per slider fatti solo con CSS 349 | 350 | Realizza slider fatti solo con CSS usando `max-height` con overflow hidden: 351 | 352 | ```css 353 | .slider { 354 | max-height: 200px; 355 | overflow-y: hidden; 356 | width: 300px; 357 | } 358 | 359 | .slider:hover { 360 | max-height: 600px; 361 | overflow-y: scroll; 362 | } 363 | ``` 364 | 365 | L'elemento si espande al valore `max-height` all'hover e lo slider diventa visibile come risultato dell'overflow. 366 | 367 | [torna al sommario](#sommario) 368 | 369 | 370 | ### Celle di tabella con larghezza uguale 371 | 372 | Lavorare con le tabelle può dare il tormento, perciò prova a usare `table-layout: fixed` per avere celle di larghezza uguale: 373 | 374 | ```css 375 | .calendar { 376 | table-layout: fixed; 377 | } 378 | ``` 379 | 380 | Layout con le tabelle e senza tormento. 381 | 382 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/jALALm) 383 | 384 | [torna al sommario](#sommario) 385 | 386 | 387 | ### Sbarazzati degli hack sui margini grazie a Flexbox 388 | 389 | Quando lavori con gli spazi tra colonne puoi sbarazzarti di `nth-`, `first-` e `last-child` usando la proprietà `space-between` di flexbox: 390 | 391 | ```css 392 | .list { 393 | display: flex; 394 | justify-content: space-between; 395 | } 396 | 397 | .list .person { 398 | flex-basis: 23%; 399 | } 400 | ``` 401 | 402 | Ora le colonne avranno sempre una spaziatura uniforme. 403 | 404 | [torna al sommario](#sommario) 405 | 406 | 407 | ### Usa il selettore d'attributo con i link senza testo 408 | 409 | Quando l'elemento `` non ha testo al suo interno ma l'attributo `href` ha un link, lo mostra: 410 | 411 | ```css 412 | a[href^="http"]:empty::before { 413 | content: attr(href); 414 | } 415 | ``` 416 | 417 | Decisamente comodo. 418 | 419 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 420 | 421 | [torna al sommario](#sommario) 422 | 423 | 424 | ### Styling dei link di "Default" 425 | 426 | Aggiunge uno stile per i link "default": 427 | 428 | ```css 429 | a[href]:not([class]) { 430 | color: #008000; 431 | text-decoration: underline; 432 | } 433 | ``` 434 | 435 | Ora i link inseriti mediante un CMS, che solitamente non hanno un attributo `class`, saranno distinti senza intaccare tutti gli altri in cascata. 436 | 437 | [torna al sommario](#sommario) 438 | 439 | 440 | ### Box con proporzioni intrinseche 441 | 442 | Per creare un contenitore con proporzioni intrinseche tutto ciò che devi fare è applicare a un div del `padding` superiore o inferiore: 443 | 444 | ```css 445 | .container { 446 | height: 0; 447 | padding-bottom: 20%; 448 | position: relative; 449 | } 450 | 451 | .container div { 452 | border: 2px dashed #ddd; 453 | height: 100%; 454 | left: 0; 455 | position: absolute; 456 | top: 0; 457 | width: 100%; 458 | } 459 | ``` 460 | 461 | Uare un `padding` del 20% rende l'altezza del contenitore pari al 20% della sua larghezza. Non importa quale sia la larghezza della finestra, il div figlio manterrà le proporzioni stabilite (100% / 20% = 5:1). 462 | 463 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/jALZvE) 464 | 465 | [torna al sommario](#sommario) 466 | 467 | 468 | ### Styling delle immagini non scaricate 469 | 470 | Rendi le immagini non scaricate più piacevoli esteticamente con un po' di CSS: 471 | 472 | ```css 473 | img { 474 | display: block; 475 | font-family: sans-serif; 476 | font-weight: 300; 477 | height: auto; 478 | line-height: 2; 479 | position: relative; 480 | text-align: center; 481 | width: 100%; 482 | } 483 | ``` 484 | 485 | Ora aggiungi le regole per gli pseudo elementi al fine di mostrare un messaggio e un riferimento URL dell'immagine non scaricata: 486 | 487 | ```css 488 | img::before { 489 | content: "Siamo spiacenti, l'immagine non è stata scaricata. :("; 490 | display: block; 491 | margin-bottom: 10px; 492 | } 493 | 494 | img::after { 495 | content: "(url: " attr(src) ")"; 496 | display: block; 497 | font-size: 12px; 498 | } 499 | ``` 500 | 501 | Ulteriori informazioni sullo styling secondo questo pattern nell'[articolo](http://bitsofco.de/styling-broken-images/) di [Ire Aderinokun](https://github.com/ireade/). 502 | 503 | [torna al sommario](#sommario) 504 | 505 | 506 | ### Usa `rem` per le grandezze globali; usa `em` per le dimensioni locali 507 | 508 | Dopo avere impostato la dimensione di base del font sull'elemento root (`html { font-size: 100%; }`), imposta la dimensione del font per gli elementi testuali con `em`: 509 | 510 | ```css 511 | h2 { 512 | font-size: 2em; 513 | } 514 | 515 | p { 516 | font-size: 1em; 517 | } 518 | ``` 519 | 520 | Poi imposta il font-size per i moduli con `rem`: 521 | 522 | ```css 523 | article { 524 | font-size: 1.25rem; 525 | } 526 | 527 | aside .module { 528 | font-size: .9rem; 529 | } 530 | ``` 531 | 532 | A questo punto ogni modulo diventa compartimentalizzato, più facile da modellare, più manutenibile e più flessibile. 533 | 534 | [torna al sommario](#sommario) 535 | 536 | 537 | ### Nascondi i video in riproduzione automatica che non sono silenziati 538 | 539 | Questo è un fantastico trucchetto per un foglio di stile personalizzato per un utente. Evita di sovraccaricare un utente col suono di un video che parte in riproduzione automatica quando la pagina viene caricata. Se il suono non è disabilitato non mostrare il video: 540 | 541 | ```css 542 | video[autoplay]:not([muted]) { 543 | display: none; 544 | } 545 | ``` 546 | 547 | Ancora una volta stiamo sfruttando la pseudo classe [`:not()`](#use-not-to-applyunapply-borders-on-navigation). 548 | 549 | [torna al sommario](#sommario) 550 | 551 | 552 | ### Usa `:root` per caratteri flessibili 553 | 554 | In un layout responsive la grandezza del carattere dovrebbe essere in grado di adattarsi a ogni risoluzione. Puoi calcolare la dimensione del font basandoti sull'altezza e sulla larghezza della finestra usando `:root`: 555 | 556 | ```css 557 | :root { 558 | font-size: calc(1vw + 1vh + .5vmin); 559 | } 560 | ``` 561 | 562 | Adesso puoi usare l'unità basata su `root em` sul valore calcolato da `:root`: 563 | 564 | ```css 565 | body { 566 | font: 1rem/1.6 sans-serif; 567 | } 568 | ``` 569 | 570 | #### [Dimostrazione](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 571 | 572 | [torna al sommario](#sommario) 573 | 574 | 575 | ### Imposta il `font-size` sugli elementi dei form per una migliore esperienza da mobile 576 | 577 | Per evitare lo zoom sugli elementi dei form dai browser mobile (iOS Safari, _et al_.) quando si tocca una ``드롭다운을 탭 할 때 HTML 폼 요소가 줌 인 되는 것을 피하기 위해 `font-size` 의 선택자 룰을 추가한다. 616 | 617 | ```css 618 | input[type="text"], 619 | input[type="number"], 620 | select, 621 | textarea { 622 | font-size: 16px; 623 | } 624 | ``` 625 | 626 | :dancer: 627 | 628 | [목차로 돌아가기](#table-of-contents) 629 | 630 | 631 |

632 | 633 | ### 포인터 이벤트를 사용한 마우스 이벤트 제어 634 | 635 | [포인터 이벤트](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events)는 터치 시 마우스 동작을 특정할 수 있도록 도와줍니다. 버튼의 디폴트 포인터를 무효화 하려면 다음 방법을 따릅니다. 636 | 637 | ```css 638 | button:disabled { 639 | opacity: .5; 640 | pointer-events: none; 641 | } 642 | ``` 643 | 644 | 아주 간단한 방법이죠? 645 | 646 | [목차로 돌아가기](#table-of-contents) 647 | 648 | 649 |
650 | 651 | ### 간격으로 사용되는 줄 바꿈에서 `display: none` 을 설정하십시오. 652 | 653 | [Harry Roberts가 지적한대로](https://twitter.com/csswizardry/status/1170835532584235008) CMS 사용자가 추가 줄 바꿈을 사용하여 간격을 두지 못하게 할 수 있습니다. 654 | 655 | ```css 656 | br + br { 657 | display: none; 658 | } 659 | ``` 660 | 661 | [목차로 돌아가기](#table-of-contents) 662 | 663 | 664 |
665 | 666 | ## 지원 667 | 668 | 최신 버전의 Chrome, Firefox, Safari, Edge에서 지원됩니다.. 669 | 670 | [목차로 돌아가기](#table-of-contents) 671 | 672 | 673 | -------------------------------------------------------------------------------- /translations/pl-PL/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # Wskazówki CSS [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | Zbiór porad, które pomogą Ci rozwinąć zawansowane umiejętności CSS. 8 | 9 | > Sprawdż takze inne wspaniałe listy [@sindresorhus](https://github.com/sindresorhus/) z [zaufanych list](https://github.com/sindresorhus/awesome/). 10 | 11 | ## Powrót do spisu treści 12 | 13 | * [Wskazówki](#Wskazowki) 14 | * [Wsparcie](#Wsparcie) 15 | * [Wskazówki dotyczące kontrybucji do tego projektu](../../CONTRIBUTING.md) 16 | 17 | 18 | ## Wskazówki 19 | 20 | 1. [Użyj resetowania CSS](#użyj-resetowania-css) 21 | 1. [Dziedziczenie `box-sizing`](#dziedziczenie-box-sizing) 22 | 1. [Użyj `unset` zamiast resetowania wszystkich ustawień](#użyj-unset-zamiast-resetowania-wszystkich-ustawień) 23 | 1. [Użyj `:not()` aby dodać/usunąć obramownie nawigacji](#użyj-not-aby-dodaćusunąć-obramownie-nawigacji) 24 | 1. [Sprawdź, czy czcionka jest zainstalowana lokalnie](#sprawdź,-czy-czcionka-jest-zainstalowana-lokalnie) 25 | 1. [Dodaj `line-height` do `body`](#dodaj-line-height-do-body) 26 | 1. [Ustaw `:focus` dla elementów formularza](#ustaw-:focus-dla-form-elements) 27 | 1. [Przesuń cokolwiek pionowo](#przesuwanie-w-pionie) 28 | 1. [Listy rozdziele przecinkami](#listy-podzielone-przecinkami) 29 | 1. [Wybierz elementy za pomocą negatywnego `nth-child`](#wybierz-przedmioty-za-pomocą-nth-child) 30 | 1. [Użyj SVG dla ikon ](#użyj-svg-dla-ikon) 31 | 1. [Użyj selektora "Lobotomized Owl"](#użyj-selektora-lobotomized-owl) 32 | 1. [Użyj `max-height` dla suwaków Pure CSS](#użyjmax-height-dla-suwaków-pure-csss) 33 | 1. [Komórki tabeli o równej-szerokości](#równoważne-komórki-tabeli) 34 | 1. [Pozbądź się marginesów za pomocą Flexbox](#pozbądź-się-marginesów-za-pomocą-flexbox) 35 | 1. [Użyj selektorów atrybutów z pustymi linkami](#użyj-selektorów-atrybutów-z-pustymi-linkami) 36 | 1. [Stylizuj domyślne linki](#stylizuj-domyślne-linki) 37 | 1. [Wewnętrzne proporcje bloków](#wewnętrzne-proporcje-bloków) 38 | 1. [Wystylizuj uszkodzone obrazy](#wystylizuj-uszkodzone-obrazy) 39 | 1. [Użyj `rem` dla ustawień globalnych rozmiarow i `em` do ustawień localnych](#użyj-rem-dla-ustawień-globalnych-rozmiarow-i-em-do-ustawień-localnych) 40 | 1. [Ukryj filmy z autoodtwarzaniem, które nie są wyciszone](#ukryj-filmy-z-autoodtwarzaniem-które-nie-są-wyciszone) 41 | 1. [Użyj `:root` dla elastycznych typów](#użyj-`:root`-dla-elastycznych-typów) 42 | 1. [Ustaw rozmiar czcionki w elementach formularza](#ustaw-rozmiar-czcionki-w-elementach-formularza) 43 | 1. [Użyj zdarzeń wskaźnika do sterowania zdarzeniami myszy](#użyj-zdarzeń-wskaźnika-do-sterowania-zdarzeniami-myszy) 44 | 1. [Ustaw `display: none` na Podziały linii używane jako odstępy](#ustaw-display-none-na-podziały-linii-używane-jako-odstępy) 45 | 46 | 47 | ### Użyj resetowania CSS 48 | 49 | Reset ustawień CSS umośliwia wymuszenie spójność stylu w różnych przeglądarkach z czystym konturem dla elementów stylizacyjnych. Możesz wykorzystać jedną bibliotek resetującej ustawienia CSS np. [Normalize](http://necolas.github.io/normalize.css/) lub użyć uproszczonego sposobu resetowania: 50 | 51 | ```css 52 | * { 53 | box-sizing: border-box; 54 | margin: 0; 55 | padding: 0; 56 | } 57 | ``` 58 | 59 | Elementy zostaną pozbawione marginesów i dopełnienia, a `box-sizing` pozwala zarządzać układami za pomocą modelu pudełkowego CSS (CSS box model). 60 | 61 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 62 | 63 | **Uwaga:** Jeżeli zdecydujesz sie na wykorzystanie powyżej opisanej wskazówki dotyczącej [Dziedziczenia `box-sizing`](#inherit-box-sizing) możesz zrezygnować z dodania `box-sizing` w zresetowanych ustawieniach CSS. 64 | 65 | [powrót do spisu treści](#powrót-do-spisu-treści ) 66 | 67 | 68 | ### Dziedziczenie `box-sizing` 69 | 70 | Niech `box-sizing` zostanie odziedziczony z `html`: 71 | 72 | ```css 73 | html { 74 | box-sizing: border-box; 75 | } 76 | 77 | *, 78 | *::before, 79 | *::after { 80 | box-sizing: inherit; 81 | } 82 | ``` 83 | 84 | Ułatwia to łatwiejszą zmianę `box-sizing` w wtyczkach lub innych komponentach, które wpływaja na inne zachowania. 85 | 86 | #### [Demonstracja](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 87 | 88 | [powrót do spisu treści](#powrót-do-spisu-treści) 89 | 90 | 91 | ### Użyj `unset` zamiast resetowania wszystkich ustawień 92 | 93 | Podczas resetowania ustawień elementu nie jest konieczne resetowanie pojedyńczych ustawień: 94 | 95 | ```css 96 | button { 97 | background: none; 98 | border: none; 99 | color: inherit; 100 | font: inherit; 101 | outline: none; 102 | padding: 0; 103 | } 104 | ``` 105 | 106 | Możesz sprecyzować wszystkie właściwości elementu, używając skrótu `all`. Używając `unset` możemy zresetować ustawienia elementu do wartości początkowych: 107 | 108 | ```css 109 | button { 110 | all: unset; 111 | } 112 | ``` 113 | 114 | [powrót do spisu treści](#powrót-do-spisu-treści) 115 | 116 | 117 | ### Użyj `:not()`, aby dodać/usunąć obramownie nawigacji 118 | 119 | Zamiast dodać obramowanie... 120 | 121 | ```css 122 | /* add border */ 123 | .nav li { 124 | border-right: 1px solid #666; 125 | } 126 | ``` 127 | 128 | ...a później usunąć ja z ostatniego elementu... 129 | 130 | ```css 131 | /* usuń obramowanie */ 132 | .nav li:last-child { 133 | border-right: none; 134 | } 135 | ``` 136 | 137 | ...użyj `:not()` pseudo-klasy, aby dodać obramowanie do wybranych elementów: 138 | 139 | ```css 140 | .nav li:not(:last-child) { 141 | border-right: 1px solid #666; 142 | } 143 | ``` 144 | 145 | Selektor CSS definiuje granicę w sposób opisany przez człowieka. 146 | 147 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/LkymvO) 148 | 149 | [powrót do spisu treści](#powrót-do-spisu-treści) 150 | 151 | 152 | ### Sprawdź, czy czcionka jest zainstalowana lokalnie 153 | 154 | Możesz sprawdzić, czy czcionka jest zainstalowana lokalnie, przed jej zdalnym pobraniem, co również jest dobrą wskazówką dotyczącą wydajności. 155 | 156 | ```css 157 | @font-face { 158 | font-family: "Dank Mono"; 159 | src: 160 | /* Full name */ 161 | local("Dank Mono"), 162 | /* Postscript name */ 163 | local("Dank-Mono"), 164 | /* Otherwise, download it! */ 165 | url("//...a.server/fonts/DankMono.woff"); 166 | } 167 | 168 | code { 169 | font-family: "Dank Mono", system-ui-monospace; 170 | } 171 | ``` 172 | 173 | Czapka dla Adama Argyle'a za podzielenie się tym prototypem i [demonstracją](https://codepen.io/argyleink/pen/VwYJpgR). 174 | 175 | [powrót do spisu treści](#powrót-do-spisu-treści) 176 | 177 | 178 | ### Dodaj `line-height` do `body` 179 | 180 | Nie musisz dodawać `wysokości linii` do każdego `

`, ``, _et al_. osobno. Zamiast tego dodaj go do `body`: 181 | 182 | ```css 183 | body { 184 | line-height: 1.5; 185 | } 186 | ``` 187 | 188 | W ten sposób elementy tekstowe mogą łatwo odziedziczyć ustawienia z `body`. 189 | 190 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 191 | 192 | [powrót do spisu treści](#Powrót-do-spisu-treści) 193 | 194 | 195 | ### Ustaw `:focus` dla elementów formularza 196 | 197 | Obserwowani użytkownicy klawiatury polegają na fokucie, aby określić, gdzie na stronie pojawiają się zdarzenia na klawiaturze. Skoncentruj się na elementach formy, które będą spójne, a następnie domyślna implementacja przeglądarki: 198 | 199 | ```css 200 | a:focus, 201 | button:focus, 202 | input:focus, 203 | select:focus, 204 | textarea:focus { 205 | box-shadow: none; 206 | outline: #000 dotted 2px; 207 | outline-offset: .05em; 208 | } 209 | ``` 210 | 211 | #### [Demonstracja](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 212 | 213 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 214 | 215 | 216 | 217 | ### Przesuwanie w pionie 218 | 219 | Nie, to nie jest czarna magia, naprawdę możesz wyśrodkować elementy w pionie: 220 | 221 | ```css 222 | html, 223 | body { 224 | height: 100%; 225 | margin: 0; 226 | } 227 | 228 | body { 229 | -webkit-align-items: center; 230 | -ms-flex-align: center; 231 | align-items: center; 232 | display: -webkit-flex; 233 | display: flex; 234 | } 235 | ``` 236 | 237 | a także używając CSS Grid: 238 | 239 | ```css 240 | body { 241 | display: grid; 242 | height: 100vh; 243 | margin: 0; 244 | place-items: center center; 245 | } 246 | ``` 247 | 248 | Chcesz coś przenieść? Pionowo, poziomo... zawsze i wszędzie? Na CSS-Tricks znajdziesz [ciekawy artykuł](https://css-tricks.com/centering-css-complete-guide/) z dobrymi instrukcje na ten temat. 249 | 250 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 251 | 252 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 253 | 254 | 255 | ### Listy podzielone przecinkami 256 | 257 | Elementy listy mogą wyglądać jak prawdziwa, oddzielona przecinkami lista: 258 | 259 | ```css 260 | ul > li:not(:last-child)::after { 261 | content: ","; 262 | } 263 | ``` 264 | 265 | Użyj `:not()` pseudo-klasy, aby przecinek nie zostal dodany do ostatniego elementu. 266 | 267 | **Uwaga:** Ta wskazówka może nie być idealna dla ułatwień dostępu, w szczególności na ekranach czytników. Kopiowanie / wklejanie z przeglądarki nie działa z treścią generowaną przez CSS. Postępuj ostrożnie. 268 | 269 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 270 | 271 | 272 | ### Wybierz przedmioty za pomocą `nth-child` 273 | 274 | Wybierz przedmioty nieparzyste za pomocą negatywnego `nth-child` w CSS, aby wybrać elementy od 1 do n. 275 | 276 | ```css 277 | li { 278 | display: none; 279 | } 280 | 281 | /* select items 1 through 3 and display them */ 282 | li:nth-child(-n+3) { 283 | display: block; 284 | } 285 | ``` 286 | 287 | Lub, skoro już nauczyłeś się trochę o użyciu [`:not()`](#use-not-to-applyunapply-borders-on-navigation),wypróbuj: 288 | 289 | ```css 290 | /* select all items except the first 3 and display them */ 291 | li:not(:nth-child(-n+3)) { 292 | display: none; 293 | } 294 | ``` 295 | 296 | To było całkiem łatwe. 297 | 298 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 299 | 300 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 301 | 302 | 303 | ### Użyj SVG dla ikon 304 | 305 | Nie ma powodu, aby nie używać SVG jako ikon: 306 | 307 | ```css 308 | .logo { 309 | background: url("logo.svg"); 310 | } 311 | ``` 312 | 313 | SVG skaluje się dobrze dla wszystkich typów rozdzielczości i jest obsługiwany we wszystkich przeglądarkach [wróć do IE9](http://caniuse.com/#search=svg). Więc porzuć swoje pliki .png, .jpg lub .gif-jif-whatev. 314 | 315 | **Uwaga:** Jeśli masz przyciski tylko ikony SVG dla widzących użytkowników, a SVG nie załaduje się, pomoże to w utrzymaniu dostępności: 316 | 317 | ```css 318 | .no-svg .icon-only::after { 319 | content: attr(aria-label); 320 | } 321 | ``` 322 | 323 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 324 | 325 | 326 | ### Użyj selektora "Lobotomized Owl" 327 | 328 | Być może "Lobotomized Owl" to dziwna nazwa dla selektora, ale użycie uniwersalnego (`*`) selektora z sąsiednim selektorem rodzeństwa (`+`) może udostepnić potężne możliwości CSS: 329 | 330 | ```css 331 | * + * { 332 | margin-top: 1.5em; 333 | } 334 | ``` 335 | 336 | W tym przykładzie wszystkie elementy, które śledzą inne elementy, otrzymają `margin-top: 1.5em`. 337 | 338 | Dowiedź sie wiecej na temat selektora "lobotomized owl" czytajac [artykul Heydon'a Pickering](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) *A List Apart*. 339 | 340 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/grRvWq) 341 | 342 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 343 | 344 | 345 | ### Użyj`max-height` (atrybutu maksymalnej wysokości) dla suwaków Pure CSS 346 | 347 | Zaimplementuj suwaki CSS używając `max-height` z ukrytym przepełnieniem: 348 | 349 | ```css 350 | .slider { 351 | max-height: 200px; 352 | overflow-y: hidden; 353 | width: 300px; 354 | } 355 | 356 | .slider:hover { 357 | max-height: 600px; 358 | overflow-y: scroll; 359 | } 360 | ``` 361 | 362 | Element rozwija się do `max-height` po najechaniu kursorem, a suwak wyświetla się w wyniku przepełnienia. 363 | 364 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 365 | 366 | 367 | ### Komórki tabeli o równej-szerokości 368 | 369 | Tworzenie tabel może być uciążliwe. Spróbuj użyć `table-layout: fixed`, aby upewnić sie, że komórki mają jednakową szerokość: 370 | 371 | ```css 372 | .calendar { 373 | table-layout: fixed; 374 | } 375 | ``` 376 | 377 | Widzisz jakie to proste! :) 378 | 379 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/jALALm) 380 | 381 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 382 | 383 | 384 | ### Pozbądź się marginesów za pomocą Flexbox 385 | 386 | Podczas pracy z rynnami kolumnowymi (column gutters) możesz pozbyć się `nth-`, `first-`, i `last-child` za pomocą właściwości`space-between`: 387 | 388 | ```css 389 | .list { 390 | display: flex; 391 | justify-content: space-between; 392 | } 393 | 394 | .list .person { 395 | flex-basis: 23%; 396 | } 397 | ``` 398 | 399 | Teraz rynny kolumnowe zawsze są rozmieszczone równomiernie. 400 | 401 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 402 | 403 | 404 | ### Użyj selektorów atrybutów z pustymi linkami 405 | 406 | Wyświetl linki, gdy element `` nie ma wartości tekstowej, ale atrybut `href` posiada link: 407 | 408 | ```css 409 | a[href^="http"]:empty::before { 410 | content: attr(href); 411 | } 412 | ``` 413 | 414 | To całkiem wygodne. 415 | 416 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 417 | 418 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 419 | 420 | 421 | ### Stylizuj "domyślne" linki 422 | 423 | Dodaj styl dla "domyślnych" linków: 424 | 425 | ```css 426 | a[href]:not([class]) { 427 | color: #008000; 428 | text-decoration: underline; 429 | } 430 | ``` 431 | 432 | Linki wstawiane za pośrednictwem CMS, które zwykle nie mają atrybutu class, będą wyróżnione bez wpływu na kaskadę. 433 | 434 | [Powrót do spisu treści](#Powrót-do-spisu-treści) 435 | 436 | 437 | ### Wewnętrzne proporcje bloków 438 | 439 | Aby utworzyć pola, które posiada wewnętrzne proporcje, wystarczy zastosować górny lub dolny margines do elementu div: 440 | 441 | ```css 442 | .container { 443 | height: 0; 444 | padding-bottom: 20%; 445 | position: relative; 446 | } 447 | 448 | .container div { 449 | border: 2px dashed #ddd; 450 | height: 100%; 451 | left: 0; 452 | position: absolute; 453 | top: 0; 454 | width: 100%; 455 | } 456 | ``` 457 | 458 | Użycie 20% wypełnienia (padding) sprawia, że wysokość bloku jest równa 20% jego szerokości. Bez względu na szerokość okna roboczego (viewport), element div zachowa swój współczynnik proporcji (100% / 20% = 5:1). 459 | 460 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/jALZvE) 461 | 462 | [powrót do spisu treści](#powrót-do-spisu-treści ) 463 | 464 | 465 | ### Wystylizuj uszkodzone obrazy 466 | 467 | Spraw, aby uszkodzone obrazy były bardziej estetyczne z użyciem odrobiny CSS: 468 | 469 | ```css 470 | img { 471 | display: block; 472 | font-family: sans-serif; 473 | font-weight: 300; 474 | height: auto; 475 | line-height: 2; 476 | position: relative; 477 | text-align: center; 478 | width: 100%; 479 | } 480 | ``` 481 | 482 | Następnie dodaj reguły pseudoelementów, aby wyświetlić komunikat użytkownika i adres URL uszkodzonego obrazu: 483 | 484 | ```css 485 | img::before { 486 | content: "We're sorry, the image below is broken :("; 487 | display: block; 488 | margin-bottom: 10px; 489 | } 490 | 491 | img::after { 492 | content: "(url: " attr(src) ")"; 493 | display: block; 494 | font-size: 12px; 495 | } 496 | ``` 497 | 498 | Dowiedz się więcej o stylizacji używając tego wzoru w oryginalnym [originalny artykule](http://bitsofco.de/styling-broken-images/) [Ire Aderinokun](https://github.com/ireade/). 499 | 500 | [powrót do spisu treści](#powrót-do-spisu-treści ) 501 | 502 | 503 | ### Użyj `rem` dla ustawień globalnych rozmiarow i `em` do ustawień localnych 504 | Po ustawieniu podstawowego rozmiaru czcionki w katalogu głównym (`html { font-size: 100%; }`), ustaw rozmiar czcionki dla elementów tekstowych na `em`: 505 | 506 | ```css 507 | h2 { 508 | font-size: 2em; 509 | } 510 | 511 | p { 512 | font-size: 1em; 513 | } 514 | ``` 515 | 516 | Następnie ustaw rozmiar czcionki dla modułów na rem`: 517 | 518 | ```css 519 | article { 520 | font-size: 1.25rem; 521 | } 522 | 523 | aside .module { 524 | font-size: .9rem; 525 | } 526 | ``` 527 | 528 | 529 | Teraz każdy moduł jest podzielony na sekcje. Sprawia to żę stylizacja i utrzymanie kodu jest łątwiejsze. 530 | 531 | [powrót do spisu treści](#powrót-do-spisu-treści ) 532 | 533 | 534 | ### Ukryj filmy z autoodtwarzaniem, które nie są wyciszone 535 | 536 | To świetna sztuczka dla niestandardowego arkusza stylów użytkownika. Unikaj przeciążania użytkownika dźwiękiem z filmu, który odtwarza się automatycznie po wczytaniu strony. Jeśli dźwięk nie jest wyciszony, nie pokazuj widea: 537 | 538 | ```css 539 | video[autoplay]:not([muted]) { 540 | display: none; 541 | } 542 | ``` 543 | 544 | 545 | Po raz kolejny wykorzystujemy pseudo-klasę [`:not()`](#use-not-to-applyunapply-borders-on-navigation) 546 | 547 | [Powrót do spisu treści](#Powrót-do-spisu-treści 548 | 549 | 550 | ### Użyj `:root` dla elastycznych typów 551 | 552 | Rozmiar czcionki typowej w elastyczny układzie (responsive layout) powinien być dostosowywany dla każdego ekranu. Możesz obliczyć rozmiar czcionki na podstawie wysokości i szerokości okna roboczego używając `:root`: 553 | 554 | ```css 555 | :root { 556 | font-size: calc(1vw + 1vh + .5vmin); 557 | } 558 | ``` 559 | 560 | Następnie możesz użyć jednostki`root em` na podstawie wartości obliczonej przez `:root`: 561 | 562 | ```css 563 | body { 564 | font: 1rem/1.6 sans-serif; 565 | } 566 | ``` 567 | 568 | #### [Demonstracja](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 569 | 570 | [powrót do spisu treści](#powrót-do-spisu-treści ) 571 | 572 | 573 | ### Ustaw rozmiar czcionki w elementach formularza 574 | 575 | Aby uniknąć korzystania z przeglądarek komórkowych (iOS Safari etc.) podczas powiększania elementów formularzy HTML, po dotknięciu menu rozwijanego `` é selecionado, adicione `font-size` no seletor: 577 | 578 | ```css 579 | input[type="text"], 580 | input[type="number"], 581 | select, 582 | textarea { 583 | font-size: 16px; 584 | } 585 | ``` 586 | 587 | :dancer: 588 | 589 | [Regressar ao índice](#Índice) 590 | 591 | 592 | ### Usa eventos de ponteiro para controlar eventos do mouse 593 | 594 | [Eventos de ponteiro](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events) permitem que você especifique como o mouse interage com o elemento que está tocando. Para desativar o evento de ponteiro padrão em um botão, por exemplo: 595 | 596 | ```css 597 | button:disabled { 598 | opacity: .5; 599 | pointer-events: none; 600 | } 601 | ``` 602 | 603 | É simples assim. 604 | 605 | [Regressar ao índice](#Índice) 606 | 607 | 608 | ### Definir `display: none` em quebras de linha usadas como espaçamento 609 | 610 | Como [Harry Roberts apontou](https://twitter.com/csswizardry/status/1170835532584235008), isso pode ajudar a impedir que os usuários do CMS usem quebras de linha extras para espaçamento: 611 | 612 | ```css 613 | br + br { 614 | display: none; 615 | } 616 | ``` 617 | 618 | [Regressar ao índice](#Índice) 619 | 620 | 621 | ## Suporte 622 | 623 | Versões atuais do Chrome, Firefox, Safari, e Edge. 624 | -------------------------------------------------------------------------------- /translations/vn-VN/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # CSS Protips [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | Một bộ gồm những tips để giúp kỹ năng CSS trở nên pro 8 | 9 | > For other great lists check out [@sindresorhus](https://github.com/sindresorhus/)'s curated list of [awesome lists](https://github.com/sindresorhus/awesome/). 10 | 11 | 12 | ## Table of Contents 13 | 14 | * [Protips](#protips) 15 | * [Support](#support) 16 | * [Translations](#translations) 17 | * [Contribution Guidelines](CONTRIBUTING.md) 18 | 19 | 20 | ## Protips 21 | 22 | 1. [Dùng CSS Reset](#dùng-css-reset) 23 | 1. [Thừa kế `box-sizing`](#thừa-kế-box-sizing) 24 | 1. [Dùng `unset` thay vì đặt lại tất cả thuộc tính](#dùng-unset-thay-vì-đặt-lại-tất-cả-thuộc-tính) 25 | 1. [Dùng `:not()` để Áp dụng/Không áp dụng các đường viền trên Điều hướng](#dùng-not-để-áp-dụngkhông-áp-dụng-các-đường-viền-trên-điều-hướng) 26 | 1. [Kiểm tra xem Phông chữ có được cài đặt cục bộ không](#kiểm-tra-xem-phông-chữ-có-được-cài-đặt-cục-bộ-không) 27 | 1. [Thêm `line-height`cho `body`](#thêm-line-height-cho-body) 28 | 1. [Đặt `:focus` cho Form Elements](#đặt-focus-cho-form-elements) 29 | 1. [Mọi thứ ở giữa theo chiều dọc](#mọi-thứ-ở-giữa-theo-chiều-dọc) 30 | 1. [Danh sách được phân tách bằng dấu phẩy](#danh-sách-được-phân-tách-bằng-dấu-phẩy) 31 | 1. [Chọn items sử dụng Negative `nth-child`](#chọn-items-sử-dụng-negative-nth-child) 32 | 1. [Dùng SVG cho Icons](#dùng-svg-cho-icons) 33 | 1. [Sử dụng "Lobotomized Owl" Selector](#sử-dụng-lobotomized-owl-selector) 34 | 1. [Dùng `max-height` cho thanh trượt CSS Sliders](#dùng-max-height-cho-thanh-trượt-css-sliders) 35 | 1. [Các ô trong bảng có chiều rộng bằng nhau](#các-ô-trong-bảng-có-chiều-rộng-bằng-nhau) 36 | 1. [Get Rid of Margin Hacks With Flexbox](#get-rid-of-margin-hacks-with-flexbox) 37 | 1. [Sử dụng thuộc tính Selectors với các liên kết trống](#sử-dụng-thuộc-tính-selectors-với-liên-kết-trống) 38 | 1. [Style "Default" Links](#style-default-links) 39 | 1. [Intrinsic Ratio Boxes](#intrinsic-ratio-boxes) 40 | 1. [Hình ảnh bị vỡ](#hình-ảnh-bị-vỡ) 41 | 1. [Dùng `rem` cho toàn cục; dùng `em` cho cục bộ](#dùng-rem-cho-toàn-cục-dùng-em-cho-cục-bộ) 42 | 1. [Ẩn các video tự động phát không bị tắt tiếng](#ẩn-các-video-tự-động-phát-không-bị-tắt-tiếng) 43 | 1. [Dùng `:root` cho Flexible Type](#dùng-root-cho-flexible-type) 44 | 1. [Đặt `font-size` trong Form Elements để có một trải nghiệm mobile tốt hơn](#đặt-font-size-trong-form-elements-để-có-một-trải-nghiệm-mobile-tốt-hơn) 45 | 1. [Dùng Pointer Events để kiểm soát mouse events](#dùng-pointer-events-để-kiểm-soát-mouse-events) 46 | 1. [Đặt `display: none` trên ngắt dòng được sử dụng làm khoảng cách](#đặt-display-none-trên-ngắt-dòng-được-sử-dụng-làm-khoảng-cách) 47 | 48 | 49 | ### Dùng CSS Reset 50 | 51 | Css resets giúp thực thi tính nhất quán về kiểu dáng trên các trình duyệt khác nhau với một phương tiện chặn rõ ràng cho các yếu tố tạo kiểu.Bạn có thể sử dụng thư viện CSS Reset như [Normalize](http://necolas.github.io/normalize.css/),hoặc bạn có thể sử dụng phương pháp đặt lại đơn giản hơn: 52 | 53 | ```css 54 | *, 55 | *::before, 56 | *::after { 57 | box-sizing: border-box; 58 | margin: 0; 59 | padding: 0; 60 | } 61 | ``` 62 | 63 | Bây giờ các phần tử sẽ bị loại bỏ magins và padding, và `box-sizing` cho phép bạn quản lý bố cục bằng CSS box model. 64 | 65 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 66 | 67 | **Note:** Nếu bạn làm theo [Inherit `box-sizing`](#inherit-box-sizing) mẹo dưới đây, bạn có thể chọn không bao gồm `box-sizing` thuộc tính trong CSS reset của bạn. 68 | 69 | [back to table of contents](#table-of-contents) 70 | 71 | 72 | ### Thừa kế `box-sizing` 73 | 74 | `box-sizing` được thừa kế từ `html`: 75 | 76 | ```css 77 | html { 78 | box-sizing: border-box; 79 | } 80 | 81 | *, 82 | *::before, 83 | *::after { 84 | box-sizing: inherit; 85 | } 86 | ``` 87 | 88 | Điều này giúp bạn dễ dàng thay đổi `box-sizing` hơn trong các plugin hoặc các thành phần khác thúc đẩy hành vi khác. 89 | 90 | #### [Demo](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 91 | 92 | [back to table of contents](#table-of-contents) 93 | 94 | 95 | ### Dùng `unset` thay vì đặt lại tất cả thuộc tính 96 | 97 | Khi đặt lại thuộc tính của một phần tử, không cần thiết phải đặt lại từng thuộc tính riêng lẻ: 98 | 99 | ```css 100 | button { 101 | background: none; 102 | border: none; 103 | color: inherit; 104 | font: inherit; 105 | outline: none; 106 | padding: 0; 107 | } 108 | ``` 109 | 110 | Bạn có thể chỉ định tất cả các thuộc tính của một phần tử bằng cách sử dụng tất cả các viết tắt. Đặt giá trị thành không đặt sẽ thay đổi thuộc tính của phần tử thành giá trị ban đầu của chúng: 111 | 112 | ```css 113 | button { 114 | all: unset; 115 | } 116 | ``` 117 | 118 | [back to table of contents](#table-of-contents) 119 | 120 | 121 | ### Dùng `:not()` để Áp dụng / Không áp dụng các đường viền trên Điều hướng 122 | 123 | Thay vì đặt trên border... 124 | 125 | ```css 126 | /* add border */ 127 | .nav li { 128 | border-right: 1px solid #666; 129 | } 130 | ``` 131 | 132 | ...và sau đó lấy nó ra khỏi phần tử cuối cùng... 133 | 134 | ```css 135 | /* remove border */ 136 | .nav li:last-child { 137 | border-right: none; 138 | } 139 | ``` 140 | 141 | ...dùng `:not()` pseudo-class để chỉ áp dụng cho các phần tử bạn muốn: 142 | 143 | ```css 144 | .nav li:not(:last-child) { 145 | border-right: 1px solid #666; 146 | } 147 | ``` 148 | 149 | Ở đây, CSS selector được đọc như một con người sẽ mô tả nó. 150 | 151 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/LkymvO) 152 | 153 | [back to table of contents](#table-of-contents) 154 | 155 | 156 | ### Kiểm tra xem Phông chữ có được cài đặt cục bộ không 157 | 158 | Bạn có thể kiểm tra xem phông chữ có được cài đặt cục bộ hay không trước khi tìm nạp từ xa, đây cũng là một mẹo hiệu suất tốt. 159 | 160 | ```css 161 | @font-face { 162 | font-family: "Dank Mono"; 163 | src: 164 | /* Full name */ 165 | local("Dank Mono"), 166 | /* Postscript name */ 167 | local("Dank-Mono"), 168 | /* Otherwise, download it! */ 169 | url("//...a.server/fonts/DankMono.woff"); 170 | } 171 | 172 | code { 173 | font-family: "Dank Mono", system-ui-monospace; 174 | } 175 | 176 | 177 | H / T tới Adam Argyle vì đã chia sẻ chú giải này và [demo](https://codepen.io/argyleink/pen/VwYJpgR). 178 | 179 | [back to table of contents](#table-of-contents) 180 | 181 | 182 | ### Thêm `line-height` cho `body` 183 | 184 | Bạn không cần thêm `line-height` cho mỗi `

`, ``... riêng biệt. Thay vào đó, hãy thêm nó vào `body`: 185 | 186 | ```css 187 | body { 188 | line-height: 1.5; 189 | } 190 | ``` 191 | 192 | Bằng cách này, các yếu tố văn bản có thể kế thừa từ `body` dễ dàng. 193 | 194 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 195 | 196 | [back to table of contents](#table-of-contents) 197 | 198 | 199 | ### Đặt `:focus` cho Form Elements 200 | 201 | Người dùng bàn phím bị cận dựa vào tiêu điểm để xác định vị trí của các sự kiện bàn phím trong trang. Làm cho tiêu điểm cho các phần tử biểu mẫu nổi bật và nhất quán sau đó triển khai mặc định của trình duyệt: 202 | 203 | ```css 204 | a:focus, 205 | button:focus, 206 | input:focus, 207 | select:focus, 208 | textarea:focus { 209 | box-shadow: none; 210 | outline: #000 dotted 2px; 211 | outline-offset: .05em; 212 | } 213 | ``` 214 | 215 | #### [Demo](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 216 | 217 | [back to table of contents](#table-of-contents) 218 | 219 | 220 | ### Mọi thứ ở giữa theo chiều dọc 221 | 222 | Không, đó không phải là ảo thuật, bạn thực sự có thể căn giữa các yếu tố theo chiều dọc.Bạn có thể làm điều này với flexbox ... 223 | 224 | ```css 225 | html, 226 | body { 227 | height: 100%; 228 | margin: 0; 229 | } 230 | 231 | body { 232 | -webkit-align-items: center; 233 | -ms-flex-align: center; 234 | align-items: center; 235 | display: -webkit-flex; 236 | display: flex; 237 | } 238 | ``` 239 | 240 | ... và với Grid cũng vậy: 241 | 242 | ```css 243 | body { 244 | display: grid; 245 | height: 100vh; 246 | margin: 0; 247 | place-items: center center; 248 | } 249 | ``` 250 | 251 | 252 | Muốn căn giữa một cái gì đó khác? Theo chiều dọc,chiều ngang ... bất cứ điều gì, mọi lúc, mọi nơi? CSS-Tricks có [a nice write-up](https://css-tricks.com/centering-css-complete-guide/) để làm được tất cả những điều đó. 253 | 254 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 255 | 256 | [back to table of contents](#table-of-contents) 257 | 258 | 259 | ### Danh sách được phân tách bằng dấu phẩy 260 | 261 | Làm cho các mục trong danh sách trông giống như một danh sách thực, được phân tách bằng dấu phẩy: 262 | 263 | ```css 264 | ul > li:not(:last-child)::after { 265 | content: ","; 266 | } 267 | ``` 268 | 269 | Dùng `:not()` pseudo-class và không có dấu phẩy nào sẽ được thêm vào mục cuối cùng. 270 | 271 | **Note:** Mẹo này có thể không lý tưởng cho khả năng tiếp cận, đặc biệt là trình đọc màn hình.Và sao chép / dán từ trình duyệt không hoạt động với nội dung do CSS tạo.Khi làm hãy thận trọng. 272 | 273 | [back to table of contents](#table-of-contents) 274 | 275 | 276 | ### Chọn items sử dụng Negative `nth-child` 277 | 278 | Sử dụng phủ định `nth-child` trong CSS để chọn các mục từ 1 đến n. 279 | 280 | ```css 281 | li { 282 | display: none; 283 | } 284 | 285 | /* select items 1 through 3 and display them */ 286 | li:nth-child(-n+3) { 287 | display: block; 288 | } 289 | ``` 290 | 291 | Hoặc,bạn đã biết một chút về [dùng `:not()`](#use-not-to-applyunapply-borders-on-navigation), thử: 292 | 293 | ```css 294 | /* select all items except the first 3 and display them */ 295 | li:not(:nth-child(-n+3)) { 296 | display: block; 297 | } 298 | ``` 299 | 300 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 301 | 302 | [back to table of contents](#table-of-contents) 303 | 304 | 305 | ### Dùng SVG cho Icons 306 | 307 | Không có lý do gì để không sử dụng SVG cho các biểu tượng: 308 | 309 | ```css 310 | .logo { 311 | background: url("logo.svg"); 312 | } 313 | ``` 314 | 315 | SVG tỉ lệ tốt cho tất cả các loại độ phân giải và được hỗ trợ trong tất cả các trình duyệt [back to IE9](http://caniuse.com/#search=svg). Loại bỏ các tệp .png, .jpg hoặc .gif-jif-whatev của bạn 316 | 317 | **Note:** Nếu bạn có các nút chỉ có biểu tượng SVG cho người dùng bị cận và SVG không tải được, điều này sẽ giúp duy trì khả năng truy cập: 318 | 319 | ```css 320 | .no-svg .icon-only::after { 321 | content: attr(aria-label); 322 | } 323 | ``` 324 | 325 | [back to table of contents](#table-of-contents) 326 | 327 | 328 | ### Sử dụng "Lobotomized Owl" Selector 329 | 330 | Nó có thể có một cái tên lạ nhưng việc sử dụng bộ chọn phổ quát (`*`) với bộ chọn anh chị em kế cận (`+`) có thể cung cấp khả năng CSS mạnh mẽ: 331 | 332 | ```css 333 | * + * { 334 | margin-top: 1.5em; 335 | } 336 | ``` 337 | 338 | Trong ví dụ này, tất cả các phần tử trong luồng dữ liệu theo sau các phần tử khác sẽ nhận được `margin-top: 1.5em`. 339 | 340 | Để biết thêm về bộ chọn "lobotomized owl", hãy đọc [Heydon Pickering's post](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls). 341 | 342 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/grRvWq) 343 | 344 | [back to table of contents](#table-of-contents) 345 | 346 | 347 | ### Dùng `max-height` cho thanh trượt CSS Sliders 348 | 349 | Áp dụng CSS-only sliders dùng `max-height` với overflow hidden: 350 | 351 | ```css 352 | .slider { 353 | max-height: 200px; 354 | overflow-y: hidden; 355 | width: 300px; 356 | } 357 | 358 | .slider:hover { 359 | max-height: 600px; 360 | overflow-y: scroll; 361 | } 362 | ``` 363 | 364 | Những thành phần sẽ được mở rộng bằng `max-height` khi di chuột và thanh trượt hiển thị do overflow. 365 | 366 | [back to table of contents](#table-of-contents) 367 | 368 | 369 | ### Các ô trong bảng có chiều rộng bằng nhau 370 | 371 | Tables có thể gây nhức đầu khi làm việc với nó. Hãy thử dùng `table-layout: fixed` để giữ cho các ô có chiều rộng bằng nhau: 372 | 373 | ```css 374 | .calendar { 375 | table-layout: fixed; 376 | } 377 | ``` 378 | 379 | Bố cục bảng dễ chịu 380 | 381 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALALm) 382 | 383 | [back to table of contents](#table-of-contents) 384 | 385 | 386 | ### Get Rid of Margin Hacks With Flexbox 387 | 388 | Khi làm việc với các rãnh cột bạn có thể loại bỏ `nth-`, `first-`, và `last-child` hack dùng flexbox's bằng `space-between` thuộc tính: 389 | 390 | ```css 391 | .list { 392 | display: flex; 393 | justify-content: space-between; 394 | } 395 | 396 | .list .person { 397 | flex-basis: 23%; 398 | } 399 | ``` 400 | 401 | Giờ đây, các rãnh cột luôn xuất hiện cách đều nhau 402 | 403 | [back to table of contents](#table-of-contents) 404 | 405 | 406 | ### Sử dụng thuộc tính Selectors với các liên kết trống 407 | 408 | Hiển thị các liên kết khi `` phần tử không có giá trị văn bản nhưng `herf` thuộc tính có một liên kết: 409 | 410 | ```css 411 | a[href^="http"]:empty::before { 412 | content: attr(href); 413 | } 414 | ``` 415 | 416 | Điều đó khá tiện lợi 417 | 418 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 419 | 420 | [back to table of contents](#table-of-contents) 421 | 422 | 423 | ### Style "Default" Links 424 | 425 | Thêm kiểu cho các liên kết "default": 426 | 427 | ```css 428 | a[href]:not([class]) { 429 | color: #008000; 430 | text-decoration: underline; 431 | } 432 | ``` 433 | 434 | Giờ đây, các liên kết được chèn qua CMS, thường không có thuộc tính `class`, sẽ có sự phân biệt mà không ảnh hưởng chung đến tầng. 435 | 436 | [back to table of contents](#table-of-contents) 437 | 438 | 439 | ### Intrinsic Ratio Boxes 440 | 441 | Để tạo một hộp có tỷ lệ nội tại, tất cả những gì bạn cần làm là áp dụng phần đệm trên cùng hoặc dưới cùng cho div: 442 | 443 | ```css 444 | .container { 445 | height: 0; 446 | padding-bottom: 20%; 447 | position: relative; 448 | } 449 | 450 | .container div { 451 | border: 2px dashed #ddd; 452 | height: 100%; 453 | left: 0; 454 | position: absolute; 455 | top: 0; 456 | width: 100%; 457 | } 458 | ``` 459 | 460 | Sử dụng 20% ​​cho phần đệm làm cho chiều cao của hộp bằng 20% ​​chiều rộng của nó. Bất kể chiều rộng của khung nhìn, div con sẽ giữ nguyên tỷ lệ co của nó (100% / 20% = 5: 1). 461 | 462 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/jALZvE) 463 | 464 | [back to table of contents](#table-of-contents) 465 | 466 | 467 | ### Hình ảnh bị vỡ 468 | 469 | Làm cho hình ảnh bị hỏng trở nên đẹp hơn về mặt thẩm mỹ với một chút CSS: 470 | 471 | ```css 472 | img { 473 | display: block; 474 | font-family: sans-serif; 475 | font-weight: 300; 476 | height: auto; 477 | line-height: 2; 478 | position: relative; 479 | text-align: center; 480 | width: 100%; 481 | } 482 | ``` 483 | 484 | Bây giờ, hãy thêm các quy tắc phần tử giả để hiển thị thông báo người dùng và tham chiếu URL của hình ảnh bị hỏng: 485 | 486 | ```css 487 | img::before { 488 | content: "We're sorry, the image below is broken :("; 489 | display: block; 490 | margin-bottom: 10px; 491 | } 492 | 493 | img::after { 494 | content: "(url: " attr(src) ")"; 495 | display: block; 496 | font-size: 12px; 497 | } 498 | ``` 499 | 500 | Tìm hiểu thêm về cách tạo kiểu cho mẫu này trong [Ire Aderinokun](https://github.com/ireade/)'s [original post](http://bitsofco.de/styling-broken-images/). 501 | 502 | [back to table of contents](#table-of-contents) 503 | 504 | 505 | ### Dùng `rem` cho toàn cục; dùng `em` cho cục bộ 506 | 507 | Sau khi đặt kích thước phông chữ cơ sở ở gốc (`html { font-size: 100%; }`), đặt kích thước phông chữ cho các yếu tố văn bản thành `em`: 508 | 509 | ```css 510 | h2 { 511 | font-size: 2em; 512 | } 513 | 514 | p { 515 | font-size: 1em; 516 | } 517 | ``` 518 | 519 | Sau đó, đặt kích thước phông chữ cho mô-đun thành `rem`: 520 | 521 | ```css 522 | article { 523 | font-size: 1.25rem; 524 | } 525 | 526 | aside .module { 527 | font-size: .9rem; 528 | } 529 | ``` 530 | 531 | Giờ đây, mỗi mô-đun trở nên được chia nhỏ và dễ tạo kiểu hơn, dễ bảo trì hơn và linh hoạt hơn. 532 | 533 | [back to table of contents](#table-of-contents) 534 | 535 | 536 | ### Ẩn các video tự động phát không bị tắt tiếng 537 | 538 | Đây là một thủ thuật tuyệt vời cho một biểu định kiểu người dùng tùy chỉnh. Tránh làm người dùng quá tải với âm thanh từ video tự động phát khi tải trang. Nếu âm thanh không bị tắt, không hiển thị video: 539 | 540 | ```css 541 | video[autoplay]:not([muted]) { 542 | display: none; 543 | } 544 | ``` 545 | 546 | Một lần nữa, chúng ta đang tận dụng lợi thế của việc sử dụng [`:not()`](#use-not-to-applyunapply-borders-on-navigation) pseudo-class. 547 | 548 | [back to table of contents](#table-of-contents) 549 | 550 | 551 | ### Dùng `:root` cho Flexible Type 552 | 553 | Kích thước phông chữ loại trong bố cục đáp ứng có thể điều chỉnh theo từng chế độ xem. Bạn có thể tính toán kích thước phông chữ dựa trên chiều cao và chiều rộng của khung nhìn bằng cách sử dụng `:root`: 554 | 555 | ```css 556 | :root { 557 | font-size: calc(1vw + 1vh + .5vmin); 558 | } 559 | ``` 560 | 561 | Bây giờ bạn có thể sử dụng `root em` đơn vị dựa trên giá trị được tính bằng `:root`: 562 | 563 | ```css 564 | body { 565 | font: 1rem/1.6 sans-serif; 566 | } 567 | ``` 568 | 569 | #### [Demo](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 570 | 571 | [back to table of contents](#table-of-contents) 572 | 573 | 574 | ### Đặt `font-size` trong Form Elements để có một trải nghiệm mobile tốt hơn 575 | 576 | Để tránh các trình duyệt di động (iOS Safari, v.v.) phóng to các phần tử biểu mẫu HTML khi ``的下拉列表时,为了避免表单元素在移动浏览器(iOS Safari 和其它)上的缩放,加上`font-size`: 581 | 582 | ```css 583 | input[type="text"], 584 | input[type="number"], 585 | select, 586 | textarea { 587 | font-size: 16px; 588 | } 589 | ``` 590 | 591 | :dancer: 592 | 593 | [回目录](#目录) 594 | 595 | 596 | ### 使用指针事件来控制鼠标事件 597 | 598 | [指针事件](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events)允许您指定鼠标如何与其触摸的元素进行交互。 要禁用按钮上的默认指针事件,例如: 599 | 600 | ```css 601 | button:disabled { 602 | opacity: .5; 603 | pointer-events: none; 604 | } 605 | ``` 606 | 607 | 就这么简单。 608 | 609 | [回目录](#目录) 610 | 611 | 612 | ### 在用作间距的换行符上设置`display: none` 613 | 614 | 正如[Harry Roberts指出](https://twitter.com/csswizardry/status/1170835532584235008),这有助于防止CMS用户使用额外的换行符 615 | 616 | ```css 617 | br + br { 618 | display: none; 619 | } 620 | ``` 621 | 622 | [回目录](#目录) 623 | 624 | ### 使用 `:empty` 隐藏空 HTML 元素 625 | 626 | 如果你有空的 HTML 元素,即内容尚未由 CMS 设置或动态注入(例如:`

`)并且它会在你的布局上创建不需要的空间,使用 `:empty` 伪类隐藏布局上的元素。 627 | 628 | ```css 629 | :empty { 630 | display: none; 631 | } 632 | ``` 633 | 634 | 注意:请记住,带有空格的元素不会被视为空元素,例如 `

`。 635 | 636 | [回目录](#目录) 637 | 638 | 639 | ### 支持情况 640 | 641 | 这些技巧适用于最新版的 Chrome, Firefox, Safari, 以及 Edge。 642 | -------------------------------------------------------------------------------- /translations/zh-TW/README.md: -------------------------------------------------------------------------------- 1 |

2 | light bulb icon 3 |

4 | 5 | # CSS 專家密技 [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) 6 | 7 | 這裡收集了一系列 CSS 專家密技,幫助你提升 CSS 技能點數。 8 | 9 | > 更多專家密技可以查看 [@sindresorhus](https://github.com/sindresorhus/) 的 [Awesome Lists](https://github.com/sindresorhus/awesome/) 10 | 11 | > 正體中文由 [Will 保哥](http://blog.miniasp.com/) 翻譯,歡迎造訪 [Will 保哥的技術交流中心](https://www.facebook.com/will.fans) 12 | 13 | 14 |
15 | 16 | ## 目錄 17 | 18 | * [專家密技](#專家密技) 19 | * [瀏覽器支援度](#瀏覽器支援度) 20 | * [貢獻準則](../../CONTRIBUTING.md) 21 | 22 | ## 專家密技 23 | 24 | 1. [使用 CSS Reset](#使用-css-reset) 25 | 1. [繼承 `box-sizing`](#繼承-box-sizing) 26 | 1. [使用 `unset` 而不是重置所有屬性](#使用-unset-而不是重置所有屬性) 27 | 1. [使用 `:not()` 選擇器來決定表單是否顯示邊框](#使用-not-選擇器來決定表單是否顯示邊框) 28 | 1. [检查字体是否在本地安装](#检查字体是否在本地安装) 29 | 1. [將 `line-height` 加入到 `body` 元素](#將-line-height-加入到-body-元素) 30 | 1. [為表單元素設定`focus`](#為表單元素設定focus) 31 | 1. [將所有元素設定垂直居中](#將所有元素設定垂直居中) 32 | 1. [逗號分隔列表](#逗號分隔列表) 33 | 1. [使用負數的 `nth-child` 來選擇元素](#使用負數的-nth-child-來選擇元素) 34 | 1. [使用 SVG 圖示](#使用-svg-圖示) 35 | 1. [使用 "貓頭鷹" 的選擇器](#使用-貓頭鷹-選擇器) 36 | 1. [使用 `max-height` 來建立純 CSS 的捲動軸](#使用-max-height-來建立純-css-的捲動軸) 37 | 1. [讓表格中每個儲存格維持等寬](#讓表格中每個儲存格維持等寬) 38 | 1. [利用 Flexbox 去除多餘的 Margin 技巧](#利用-flexbox-去除多餘的-margin-技巧) 39 | 1. [利用屬性選擇器填滿空白連結的文字內容](#利用屬性選擇器填滿空白連結的文字內容) 40 | 1. [幫沒有類別的連結設定一個預設樣式](#幫沒有類別的連結設定一個預設樣式) 41 | 1. [等比例的方塊](#等比例的方塊) 42 | 1. [為破圖定義樣式](#為破圖定義樣式) 43 | 1. [用 `rem` 來調整全域大小;用 `em` 來調整區域大小](#用-rem-來調整全域大小用-em-來調整區域大小) 44 | 1. [隱藏沒有靜音並設定自動播放的影片](#隱藏沒有靜音並設定自動播放的影片) 45 | 1. [使用 `:root` 選擇器來設定彈性的字體大小](#使用-root-選擇器來設定彈性的字體大小) 46 | 1. [為了更好的行動體驗來設定表單元素的 `font-size`](#為了更好的行動體驗來設定表單元素的-font-size) 47 | 1. [使用指標事件來控制滑鼠事件](#使用指標事件來控制滑鼠事件) 48 | 1. [在用作間距的換行符上設置`display: none`](#在用作間距的換行符上設置display-none) 49 | 50 | 51 | ### 使用 CSS Reset 52 | 53 | CSS Reset 可以幫你在不同的瀏覽器上維持一致的樣式風格。你可以使用像 [Normalize](http://necolas.github.io/normalize.css/) 這類的 CSS Reset 套件,或使用更簡潔的 CSS Reset 方法: 54 | 55 | ```css 56 | *, 57 | *::before, 58 | *::after { 59 | box-sizing: border-box; 60 | margin: 0; 61 | padding: 0; 62 | } 63 | ``` 64 | 65 | 現在元素的 margin 和 padding 已重設,且 `box-sizing` 可以讓你透過 CSS Box Model 管理版面配置。 66 | 67 | #### [示範](http://codepen.io/AllThingsSmitty/pen/kkrkLL) 68 | 69 | 注意:如果你接著套用 [繼承 `box-sizing`](#繼承-box-sizing) 這個技巧, 你或許不需要在你的 CSS Reset 中加入 `box-sizing` 屬性。 70 | 71 | [回到目錄](#table-of-contents) 72 | 73 | ### 繼承 `box-sizing` 74 | 75 | 讓 `box-sizing` 屬性自動從 `html` 元素繼承下來 : 76 | 77 | ```css 78 | html { 79 | box-sizing: border-box; 80 | } 81 | 82 | *, 83 | *::before, 84 | *::after { 85 | box-sizing: inherit; 86 | } 87 | ``` 88 | 89 | 如此一來,你就很容易的在其他外掛或元件裡改變 `box-sizing` 的值。 90 | 91 | #### [示範](https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/) 92 | 93 | [回到目錄](#table-of-contents) 94 | 95 | ### 使用 `unset` 而不是重置所有屬性 96 | 97 | 當重置元素的屬性時,並不需要重置元素中每個屬性: 98 | 99 | ```css 100 | button { 101 | background: none; 102 | border: none; 103 | color: inherit; 104 | font: inherit; 105 | outline: none; 106 | padding: 0; 107 | } 108 | ``` 109 | 110 | 你可以用 `all` 來代表元素中所有的樣式屬性。 將該值設定為 `unset` 意味著將元素中所有樣式屬性回復到預設值: 111 | 112 | ```css 113 | button { 114 | all: unset; 115 | } 116 | ``` 117 | 118 | [回到目錄](#table-of-contents) 119 | 120 | ### 使用 `:not()` 選擇器來決定表單是否顯示邊框 121 | 122 | 假設你用以下樣式先替元素新增邊框 123 | 124 | ```css 125 | /* 新增邊框 */ 126 | .nav li { 127 | border-right: 1px solid #666; 128 | } 129 | ``` 130 | 131 | 然後在最後一個元素去除邊框 132 | 133 | ```css 134 | /* 去掉邊框 */ 135 | .nav li:last-child { 136 | border-right: none; 137 | } 138 | ``` 139 | 140 | 不過你可以改用 `:not()` 偽類別 (pseudo-class) 來做到完全相同的效果: 141 | 142 | ```css 143 | .nav li:not(:last-child) { 144 | border-right: 1px solid #666; 145 | } 146 | ``` 147 | 148 | CSS選擇器以人類描述它的方式定義邊界。 149 | 150 | #### [示範](http://codepen.io/AllThingsSmitty/pen/LkymvO) 151 | 152 | [回到目錄](#table-of-contents) 153 | 154 | 155 | ### 检查字体是否在本地安装 156 | 157 | 您可以在远程获取字体之前检查是否在本地安装了字体,这也是一个很好的性能提示。 158 | 159 | ```css 160 | @font-face { 161 | font-family: "Dank Mono"; 162 | src: 163 | /* Full name */ 164 | local("Dank Mono"), 165 | /* Postscript name */ 166 | local("Dank-Mono"), 167 | /* Otherwise, download it! */ 168 | url("//...a.server/fonts/DankMono.woff"); 169 | } 170 | 171 | code { 172 | font-family: "Dank Mono", system-ui-monospace; 173 | } 174 | ``` 175 | 176 | 亚当·阿盖尔(Adam Argyle)的帽子技巧,分享了这个技巧和[例子](https://codepen.io/argyleink/pen/VwYJpgR). 177 | 178 | [回到目錄](#table-of-contents) 179 | 180 | 181 | ### 將 `line-height` 加入到 `body` 元素 182 | 183 | 你不必為分別為每一個 `

`、`` 元素加入 `line-height` 樣式,相反的,你應該直接新增到 `body` 元素: 184 | 185 | ```css 186 | body { 187 | line-height: 1.5; 188 | } 189 | ``` 190 | 191 | 所有的文字元素預設就會繼承 `body` 的樣式。 192 | 193 | #### [示範](http://codepen.io/AllThingsSmitty/pen/VjbdYd) 194 | 195 | [回到目錄](#table-of-contents) 196 | 197 | 198 | ### 為表單元素設定`focus` 199 | 200 | 視力正常的鍵盤使用者依靠焦點來確認鍵盤事件在頁面中的位置。使表單元素的焦點脫穎而出,然後與瀏覽器的預設實作保持一致: 201 | 202 | ```css 203 | a:focus, 204 | button:focus, 205 | input:focus, 206 | select:focus, 207 | textarea:focus { 208 | box-shadow: none; 209 | outline: #000 dotted 2px; 210 | outline-offset: .05em; 211 | } 212 | ``` 213 | 214 | #### [Demo](https://codepen.io/AllThingsSmitty/pen/ePzoOP/) 215 | 216 | [回到目錄](#table-of-contents) 217 | 218 | 219 | ### 將所有元素設定垂直居中 220 | 221 | 不!這絕不是黑魔法,這真的可以將所有元素設定垂直居中: 222 | 223 | ```css 224 | html, 225 | body { 226 | height: 100%; 227 | margin: 0; 228 | } 229 | 230 | body { 231 | -webkit-align-items: center; 232 | -ms-flex-align: center; 233 | align-items: center; 234 | display: -webkit-flex; 235 | display: flex; 236 | } 237 | ``` 238 | 239 | ...還有 CSS Grid: 240 | 241 | ```css 242 | body { 243 | display: grid; 244 | height: 100vh; 245 | margin: 0; 246 | place-items: center center; 247 | } 248 | ``` 249 | 250 | 還想居中排版其他的東西?垂直居中、水平居中、... 任何事、任何時間、任何地點?CSS-Tricks [有篇不錯的文章](https://css-tricks.com/centering-css-complete-guide/) 提到了各種居中排版的技巧。 251 | 252 | #### [示範](http://codepen.io/AllThingsSmitty/pen/GqmGqZ) 253 | 254 | [回到目錄](#table-of-contents) 255 | 256 | ### 逗號分隔列表 257 | 258 | 使列表的每項都由逗號分隔: 259 | 260 | ```css 261 | ul > li:not(:last-child)::after { 262 | content: ','; 263 | } 264 | ``` 265 | 266 | 列表中最後一項不用加逗號,所以可以使用 `:not()` 偽類別 (pseudo-class) 。 267 | 268 | **注意:**這一技巧對於無障礙網頁,特別是螢幕閱讀器而言,並不理想。而且預設要複製貼網頁內容時,並不會包含 CSS 動態產生的內容,這點必須特別注意。 269 | 270 | [回到目錄](#table-of-contents) 271 | 272 | ### 使用負數的 `nth-child` 來選擇元素 273 | 274 | 使用負數的 `nth-child` 可以選擇 1 至 n 個元素。 275 | 276 | ```css 277 | li { 278 | display: none; 279 | } 280 | 281 | /* 選擇第 1 至第 3 個元素並顯示出來 */ 282 | li:nth-child(-n+3) { 283 | display: block; 284 | } 285 | ``` 286 | 287 | 或者,你已經知道 [使用 `:not()` 選擇器來決定表單是否顯示邊框](#使用-not-選擇器來決定表單是否顯示邊框) 這個技巧,你可以試試: 288 | 289 | ```css 290 | /* 選擇除了前 3 個之外的所有項目,並顯示出來 */ 291 | li:not(:nth-child(-n + 3)) { 292 | display: none; 293 | } 294 | ``` 295 | 296 | 就是這麼簡單! 297 | 298 | #### [示範](http://codepen.io/AllThingsSmitty/pen/WxjKZp) 299 | 300 | [回到目錄](#table-of-contents) 301 | 302 | ### 使用 SVG 圖示 303 | 304 | 沒有理由不使用 SVG 圖示: 305 | 306 | ```css 307 | .logo { 308 | background: url('logo.svg'); 309 | } 310 | ``` 311 | 312 | SVG 在所有解析度下都可以良好縮放,並且支援 IE9 之後的所有瀏覽器,丟棄你的 .png, .jpg, 或 .gif 檔案! 313 | 314 | **注意:** 如果你有一個只用 SVG 圖示的按鈕,只給看的見的人來點選。當 SVG 無法載入的時候,以下樣式可以幫助你維持網頁的可及性(Accessibility): 315 | 316 | ```css 317 | .no-svg .icon-only::after { 318 | content: attr(aria-label); 319 | } 320 | ``` 321 | 322 | [回到目錄](#table-of-contents) 323 | 324 | ### 使用 "貓頭鷹" 選擇器 325 | 326 | 這個名字 "Lobotomized Owl" (貓頭鷹) 大家可能比較陌生,不過如果你將 通用選擇器 (`*`) 和 相鄰兄弟選擇器 (`+`) 一起使用的話,將可帶來極大效益: 327 | 328 | ```css 329 | * + * { 330 | margin-top: 1.5em; 331 | } 332 | ``` 333 | 334 | 在此範例中,在檔案中所有的元素,只要緊接著其他元素,就會套用一個 `margin-top: 1.5em` 樣式。 335 | 336 | 更多 "貓頭鷹" (Lobotomized Owl) 選擇器,可參考 *A List Apart* 上面關於 [Heydon Pickering 的文章](http://alistapart.com/article/axiomatic-css-and-lobotomized-owls) 337 | 338 | #### [示範](http://codepen.io/AllThingsSmitty/pen/grRvWq) 339 | 340 | [回到目錄](#table-of-contents) 341 | 342 | ### 使用 `max-height` 來建立純 CSS 的捲動軸 343 | 344 | 你可以透過 `max-height` 與 `overflow-y: hidden` 來實作出 CSS-only 的捲動軸: 345 | 346 | ```css 347 | .slider { 348 | max-height: 200px; 349 | overflow-y: hidden; 350 | width: 300px; 351 | } 352 | 353 | .slider:hover { 354 | max-height: 600px; 355 | overflow-y: scroll; 356 | } 357 | ``` 358 | 359 | 當滑鼠移到 `.slider` 的元素時,元素的內容如果過多,最大高度只會擴展到 `max-height` 的值,而且會自動顯示捲動軸。 360 | 361 | [回到目錄](#table-of-contents) 362 | 363 | ### 讓表格中每個儲存格維持等寬 364 | 365 | 表格中要維持每一格都等寬是一件痛苦的事,所以你應該嘗試用 `table-layout: fixed` 來讓所有儲存格維持等寬: 366 | 367 | ```css 368 | .calendar { 369 | table-layout: fixed; 370 | } 371 | ``` 372 | 373 | 這才是無痛的 Table 版面配置。 374 | 375 | #### [示範](http://codepen.io/AllThingsSmitty/pen/jALALm) 376 | 377 | [回到目錄](#table-of-contents) 378 | 379 | ### 利用 Flexbox 去除多餘的 Margin 技巧 380 | 381 | 排版的時候,為了設計出每一欄的間隙 (gutters),一般都會用到像是 `nth-`、`first-` 和 `last-child` 的技巧,來去除頭尾多餘的間隙,不如使用 Flexbox 的 `space-between` 屬性: 382 | 383 | ```css 384 | .list { 385 | display: flex; 386 | justify-content: space-between; 387 | } 388 | 389 | .list .person { 390 | flex-basis: 23%; 391 | } 392 | ``` 393 | 394 | 現在,每一欄之間的間隙將會平均分佈。 395 | 396 | [回到目錄](#table-of-contents) 397 | 398 | ### 利用屬性選擇器填滿空白連結的文字內容 399 | 400 | 當 `` 元素沒有文字內容,但有 `href` 屬性的時候,可以這樣做: 401 | 402 | ```css 403 | a[href^='http']:empty::before { 404 | content: attr(href); 405 | } 406 | ``` 407 | 408 | 這真的非常方便。 409 | 410 | #### [示範](http://codepen.io/AllThingsSmitty/pen/zBzXRx) 411 | 412 | [回到目錄](#table-of-contents) 413 | 414 | ### 幫沒有類別的連結設定一個預設樣式 415 | 416 | 幫沒有套用 class 的超連結設定一個預設樣式: 417 | 418 | ```css 419 | a[href]:not([class]) { 420 | color: #008000; 421 | text-decoration: underline; 422 | } 423 | ``` 424 | 425 | 使用者透過後台 CMS 系統插入的超連結通常沒有 `class` 屬性,以上樣式可以針對這些超連結進行設定,且不會影響其它樣式定義。 426 | 427 | [回到目錄](#table-of-contents) 428 | 429 | ### 等比例的方塊 430 | 431 | 要建立一個固定比例的方塊 (Box),你需要的就是將 `padding-top` 或 `padding-bottom` 設定到 div 元素: 432 | 433 | ```css 434 | .container { 435 | height: 0; 436 | padding-bottom: 20%; 437 | position: relative; 438 | } 439 | 440 | .container div { 441 | border: 2px dashed #ddd; 442 | height: 100%; 443 | left: 0; 444 | position: absolute; 445 | top: 0; 446 | width: 100%; 447 | } 448 | ``` 449 | 450 | 在 `padding-bottom` 設定 `20%` 意味著各個 div 方塊的高度等同於 20% 的寬度。無論 Viewport 現在的寬度多少,子元素的 div 將維持其寬高比(100% / 20% = 5:1)。 451 | 452 | #### [示範](http://codepen.io/AllThingsSmitty/pen/jALZvE) 453 | 454 | [回到目錄](#table-of-contents) 455 | 456 | ### 為破圖定義樣式 457 | 458 | 只要一點 CSS 就可以美化所有破圖: 459 | 460 | ```css 461 | img { 462 | display: block; 463 | font-family: sans-serif; 464 | font-weight: 300; 465 | height: auto; 466 | line-height: 2; 467 | position: relative; 468 | text-align: center; 469 | width: 100%; 470 | } 471 | ``` 472 | 473 | 接著新增一個 偽元素規則 (pseudo-elements rules) 來顯示使用者訊息,以及這張破圖的 URL 參考: 474 | 475 | ```css 476 | img::before { 477 | content: "We're sorry, the image below is broken :("; 478 | display: block; 479 | margin-bottom: 10px; 480 | } 481 | 482 | img::after { 483 | content: '(url: ' attr(src) ')'; 484 | display: block; 485 | font-size: 12px; 486 | } 487 | ``` 488 | 489 | 想學習更多這類樣式技巧,可以參考 [Ire Aderinokun](https://github.com/ireade/) 的 [原始文章](http://bitsofco.de/styling-broken-images/)。 490 | 491 | [回到目錄](#table-of-contents) 492 | 493 | ### 用 `rem` 來調整全域大小;用 `em` 來調整區域大小 494 | 495 | 在根元素設定基礎字體大小後 (`html { font-size: 100%; }`), 使用 `em` 設定文字元素的字體大小: 496 | 497 | ```css 498 | h2 { 499 | font-size: 2em; 500 | } 501 | 502 | p { 503 | font-size: 1em; 504 | } 505 | ``` 506 | 507 | 然後設定模組的字體大小為 `rem`: 508 | 509 | ```css 510 | article { 511 | font-size: 1.25rem; 512 | } 513 | 514 | aside .module { 515 | font-size: 0.9rem; 516 | } 517 | ``` 518 | 519 | 現在,每個模組變得獨立,更容易、靈活的樣式便於維護。 520 | 521 | [回到目錄](#table-of-contents) 522 | 523 | ### 隱藏沒有靜音並設定自動播放的影片 524 | 525 | 當你在一個可以自訂樣式的後台環境設定網站樣式時,這是一個不錯的小技巧。畢竟自動撥放影片是蠻惱人的,這個技巧可以幫助你避免影片在沒有靜音的情況下自動撥放。 526 | 527 | ```css 528 | video[autoplay]:not([muted]) { 529 | display: none; 530 | } 531 | ``` 532 | 533 | 你看,我們再次利用了 [`:not()`](#使用-not-選擇器來決定表單是否顯示邊框) 偽類別 (pseudo-class) 的優勢。 534 | 535 | [回到目錄](#table-of-contents) 536 | 537 | ### 使用 `:root` 選擇器來設定彈性的字體大小 538 | 539 | 在響應式版面(responsive layout)中,字體大小通常需要根據不同的 Viewport (畫面大小) 進行調整。你可以根據 `:root` 所定義的 Viewport 高度與寬度來調整字體大小: 540 | 541 | ```css 542 | :root { 543 | font-size: calc(1vw + 1vh + 0.5vmin); 544 | } 545 | ``` 546 | 547 | 現在你便能使用依 `:root` 字級為基準的 `rem` 單位了。 548 | 549 | ```css 550 | body { 551 | font: 1rem/1.6 sans-serif; 552 | } 553 | ``` 554 | 555 | #### [示範](http://codepen.io/AllThingsSmitty/pen/XKgOkR) 556 | 557 | [回到目錄](#table-of-contents) 558 | 559 | ### 為了更好的行動體驗來設定表單元素的 `font-size` 560 | 561 | 為了避免使用者在行動瀏覽器 (iOS Safari, 等等)點擊 `