Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A few things you need to know about CSS

A few things you need to know about CSS

Outline

Brief introduction to CSS
CSS magic: graphical shapes out of regular HTML elements, CSS instead of JavaScript
Survival hints: what you rather don’t do with CSS
Level up! How to get on with CSS and be happy

Dmitry Sheiko

April 13, 2015
Tweet

More Decks by Dmitry Sheiko

Other Decks in Programming

Transcript

  1. <h1>
 <a>
 <em>Hello</em>
 </a>
 </h1> h1 em { color: yellow;

    } h1 a em { color: yellow; } h1 a > em { color: yellow; } HTML CSS OUTPUT Hello World
  2. <body>
 <h1>
 <em>Hello</em>
 </h1>
 </body> body { color: white; }

    h1 { color: yellow; } HTML CSS OUTPUT Hello World
  3. <h1 class="parent">
 <em class="child">
 Hello World
 </em>
 </h1> .parent .child

    { color: white; } h1 em { color: yellow; } HTML CSS OUTPUT
  4. <h1 class="parent">
 <em class="child">
 Hello World
 </em>
 </h1> .parent .child

    { color: white; } h1 em { color: yellow; } HTML CSS OUTPUT Hello World
  5. <div></div> div{ width: 0; height: 0; border-width: 200px; border-style: solid;

    border-color: transparent; border-top-color: yellow; } HTML CSS OUTPUT
  6. <div></div> div{ width: 0; height: 0; border-width: 200px; border-style: solid;

    border-color: transparent; border-top-color: yellow; border-right-color: red; border-bottom-color: white; border-left-color: green; } HTML CSS OUTPUT
  7. On :target <div id=“login“ class="login"></div> .login { display: none; }

    .login:target { display: block; } HTML CSS OUTPUT
  8. Checkbox hack <label for=“menu-state" /> <input type=“checkbox" id=“menu-state" class=“menu-state"/> <div

    class=“menu-view"></div> .menu-view, .menu-state { display: none; } .menu-state:checked + .menu-view { display: block; } HTML CSS
  9. Checkbox hack • Custom Radio Buttons and Checkboxes • Tree

    menu • Tabbed areas • Dropdown menus • Push Toggles
  10. Avoid CSS inline styles <tr> <td style="padding: 0;"> <p style="margin-top:

    10px; line-height: 180%; font-family: Arial, Tahoma; font-size: 12px; color: #868484"> lorem ipsum </p> <p style="background: #EEE; padding: 10px; margin-top: 20px; line- height: 180%; font-family: Arial, Tahoma; font-size: 12px; color: #868484"> lorem ipsum HTML
  11. Do not use IDs for styling BAD <div id="widget"> 


    <div> 
 #widget { border: 1px solid #357ebd; } GOOD <div class="widget"> 
 <div> 
 .widget { border: 1px solid #357ebd; } CSS CSS
  12. Never use !important reactively BAD .toolbar .btn { border: none

    !important; } .btn { border: 1px solid #357ebd; width: 200px; }
 CSS
  13. Do not override styles, but extend BAD .btn { border:

    1px solid #357ebd; width: 200px; } 
 .toolbar .btn { border: none; } GOOD .btn { width: 200px; } 
 .btn-outlined { border: 1px solid #357ebd; } CSS CSS
  14. h2 h2 h2 h2 h2 h2 h2 h2 h2 li

    li li li li li li li li li ul ul ul u nav nav CSS
  15. h2 h2 h2 h2 h2 h2 h2 h2 h2 li

    li li li li li li li li li ul ul ul u nav nav .feed CSS
  16. h2 h2 h2 h2 h2 h2 h2 h2 h2 li

    li li li li li li li li li ul ul ul u nav nav .feed CSS
  17. /* Global scope */ html { font-size: 62.5%; /* 10px

    */ } /* Components */ .header { font-size: 1.6rem; } /* scale with components */ h1 { font-size: 2em; } Lorem ipsum Lorem ipsum 16px h1: 32px .header CSS OUTPUT
  18. /* Global scope */ @media (max-width: 960px) { html {

    font-size: 56.25%; /*9px*/ } } /* Components */ .header { font-size: 1.6rem; } /* scale with components */ h1 { font-size: 2em; } Lorem ipsum Lorem ipsum 14.4px h1: 28.8px .header CSS OUTPUT
  19. @import "./main-menu.css"; @import "./panel.css"; MAIN.CSS PANEL.CSS /* Here go style

    for panel widget only */ .panel { } BUTTONS.CSS /* Here go styles for any buttons used in the project */ .btn { } @import "./buttons.css";