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

Programming WTF: HTML & CSS

Programming WTF: HTML & CSS

Teaching HTML & CSS to people who never saw code before.

Fernando Mendes

April 14, 2016
Tweet

More Decks by Fernando Mendes

Other Decks in Programming

Transcript

  1. Programming
    wat the f*ck!?

    View Slide

  2. FRANCISCO RIBEIRO
    MARTINHO ARAGÃO PAULO CARDOSO
    martinhoaragao.me
    FERNANDO MENDES
    @fribmendes
    @frmendes
    @FranciscoRibeiro
    @pcardosolei

    View Slide

  3. HTML

    View Slide

  4. HTML
    Hyper Text Markup Language

    View Slide

  5. HTML
    Hyper Text Markup Language

    View Slide

  6. HTML
    Hyper Text Markup Language
    Not really programming™.
    Sorry :(

    View Slide

  7. View Slide




  8. View Slide




  9. Tags
    remember those,
    we’re going to
    use them a lot

    View Slide

  10. HTML
    head
    body

    View Slide








  11. View Slide








  12. View Slide








  13. Language
    Language

    View Slide








  14. Language
    Title
    Language

    View Slide








  15. Language
    Title
    Language
    Author

    View Slide








  16. Language
    Title
    Language
    Author
    Info
    Links
    Style

    View Slide








  17. Language
    Title
    Language
    Author
    Info
    Links
    Style
    Metadata

    View Slide

  18. TITLE
    My first webpage
    Sets the page’s title

    View Slide


  19. Meta-information
    META

    View Slide


  20. Meta-information
    your first self-closing tag!
    META

    View Slide

  21. META

    More Meta-information
    Search engines say “thank you”

    View Slide


  22. Adds cool stuff to the webpage
    LINK

    View Slide


  23. Adds cool stuff to the webpage
    LINK

    View Slide








  24. View Slide








  25. View Slide








  26. View Slide








  27. View Slide








  28. pretty much
    everything

    View Slide

  29. SHOWTIME

    View Slide

  30. EX 1

    View Slide

  31. 1. Create a directory with an index.html file. All code goes here.
    2. Add the DOCTYPE and html tags.
    3. Add the head and the body tags.
    4. Set the title to “My first webpage”.
    5. Add a tag that tells us you’re the author.
    6. Use ‘utf-8’ as the charset.
    7. Write something in the body.
    EX 1

    View Slide

  32. 1. Create a directory with an index.html file. All code goes here.
    2. Add the DOCTYPE and html tags.
    3. Add the head and the body tags.
    4. Set the title to “My first webpage”.
    5. Add a tag that tells us you’re the author.
    6. Use ‘utf-8’ as the charset.
    7. Write something in the body.
    Tips:
    1. Drag the file to your browser to open it.
    2. Go slow and refresh when you add something new!
    3. The favicon is here: http://bit.ly/1qmRtbB You’ll need it! :)
    4. Check mdn if you need to know what’s inside a tag:

    https://developer.mozilla.org
    5. Call for us and ask us questions! We love attention!
    EX 1

    View Slide




  33. My first webpage





    Hello, world!


    EX 1

    View Slide

  34. Think of MS Word’s title
    This is a heading
    HEADINGS

    View Slide

  35. Think of MS Word’s subtitle
    This is a heading
    This is also a heading
    HEADINGS

    View Slide

  36. This is a heading
    This is also a heading
    And this
    Uh… Does anyone know if MS Word has
    subsubtitles?
    HEADINGS

    View Slide

  37. It’s headings all the way down!

    This is a heading
    This is also a heading
    And this
    HEADINGS

    View Slide

  38. This is a paragraph
    PARAGRAPHS

    View Slide

  39. This is a paragraph

    This is also
    a paragraph

    PARAGRAPHS

    View Slide

  40. This is a paragraph

    This is also
    a paragraph

    But this isn’t. Try to do this!
    Add the previous code to your index.html file
    PARAGRAPHS

    View Slide

  41. ANCHORS
    Our website!
    You may know them as “links”

    View Slide

  42. Our website!
    meet attributes!
    Attributes add invisible information for some tags to
    work.
    ANCHORS

    View Slide

  43. LISTS

    First Item
    Second Item
    Third Item


    An Item
    Another Item
    Also an Item

    Lists can be ordered or unordered

    View Slide

  44. 1. First Item
    2. Second Item
    3. Third Item
    • An Item
    • Another Item
    • Also an Item
    Lists can be ordered or unordered
    LISTS

    View Slide


  45. First Item
    Second Item
    Third Item


    An Item
    Another Item
    Also an Item

    “Main” tag tells us the list type
    List is only visible when we add list items:
    LISTS

    View Slide

  46. EX 2

    View Slide

  47. 1. Add a heading to index.html. Make it about your personal webpage.
    2. Create an unordered list.
    3. Each list item should be a (smaller) heading and a paragraph.
    4. Make it so that each heading is inside an anchor.
    EX 2

    View Slide


  48. CeSIUM


    Meet CeSIUM!
    We’re a friendly bunch!


    We love what we do
    Which is basically play XBox all day…



    EX 2

    View Slide

  49. IMAGES

    We don’t need to add any content to an image.
    So, it’s a self-closing tag!
    Source can also be a URL

    View Slide

  50. DIV
    We can add more content here!
    Divs are containers.
    They keep a bunch of elements together as group.
    Also, they’re usually just boxes.

    View Slide

  51. DIV

    View Slide

  52. Wait, what? Nothing changed
    DIV

    View Slide


  53. We can add more content here!

    Don’t mind this, it’s just CSS.
    We’ll deal with that later.
    DIV

    View Slide

  54. DIV

    View Slide

  55. EX 3

    View Slide

  56. 1. Wrap the body content in a div. Don’t forget to indent!
    2. Before the div you just added, create a another.
    3. Add an image and a small bio inside this new div.

    Remember you can use a URL for the image source!
    EX 3

    View Slide




  57. CeSIUM: Awesome since 1995


    CeSIUM


    Meet CeSIUM!
    We’re a friendly bunch!





    EX 3

    View Slide

  58. So far…
    Think of HTML
    like the blueprint of a house…
    We have everything in place
    but it isn’t very pretty, is it?

    View Slide

  59. CSS

    View Slide

  60. CSS
    Cascading Style Sheets

    View Slide

  61. CSS
    Cascading Style Sheets

    View Slide


  62. Add this to the head
    Also, create this file
    and directory
    LINK

    View Slide

  63. SYNTAX
    selector { attribute: value; }

    View Slide

  64. selector { attribute: value; }
    Make every paragraph red and with a 16 pixel size
    p {
    color: red;
    font-size: 16px;
    }
    SYNTAX

    View Slide

  65. SELECTORS
    div { ... }
    Element selector
    Applies style to
    every element of
    kind

    Applies to me!


    Not to me!

    View Slide

  66. SELECTORS
    #id { ... }
    Id selector
    Applies style to that
    particular element

    Applies to me!


    Not to me!

    div { ... }
    Element selector
    Applies style to
    every element of
    kind

    Applies to me!


    Not to me!

    View Slide

  67. SELECTORS
    .red { ... }
    Class selector
    Applies style to
    every element of
    class

    Applies to me!


    And to me!

    #myDiv { ...
    }
    Id selector
    Applies style to that
    particular element

    Applies to me!


    Not to me!

    div { ... }
    Element selector
    Applies style to
    every element of
    kind

    Applies to me!


    Not to me!

    View Slide

  68. TEXT
    p {
    font-family: ‘Open Sans’, sans-serif;
    font-size: 16px;
    }
    Tries the first one.
    If the font isn’t available goes to the next

    View Slide

  69. IMG
    img {
    height: 150px;
    width: 150px;
    }
    Usually one is enough to keep the aspect ratio

    View Slide

  70. EX 4

    View Slide

  71. 1. Remember the divs we added? Add a class called info to the first one

    and a class called content to the second one.
    2. Add an id to the image. Name it whatever you want,

    but make it suggestive enough for everyone to understand!
    3. Change the font-family of every paragraph to ‘Open Sans’.
    4. Do the same for every heading (remember we have h1 and h2),

    but set it to ‘Oswald’ instead! Make them 30px and 24px respectively.
    5. Make the img have a width of 150px.
    Tips:
    1. Google Fonts is a great source of awesome fonts!

    Both Oswald and Open Sans can be found there.
    2. Add the fonts to your collection.
    3. Add the resulting link tag to your index.html file
    EX 4

    View Slide




  72. CeSIUM: Awesome since 1995


    CeSIUM


    Meet CeSIUM!
    We’re a friendly bunch!





    EX 4

    View Slide

  73. p {
    font-family: 'Open Sans', sans-serif;
    }
    h1, h2 {
    font-family: 'Oswald', sans-serif;
    }
    h1 {
    font-size: 30px;
    }
    h2 {
    font-size: 24px;
    }
    #logo {
    width: 150px;
    }
    body {
    /* Small trick to have simple
    * browser compatibility */
    margin: 0;
    padding: 0;
    }
    EX 4

    View Slide

  74. SELECTORS II
    .content p { ... }


    Applies to me!



    Not to me!

    View Slide

  75. .content div p { ... }
    Element selector



    Applies to me!



    Not to me!


    SELECTORS II

    View Slide

  76. .content a:hover { ... }


    Applies to me!
    But only when the cursor is on top of me!


    SELECTORS II

    View Slide

  77. p {
    font-style: italic;
    text-decoration: underline;
    }
    TEXT II

    View Slide

  78. a {
    font-weight: bold;
    text-decoration: none;
    }
    TEXT II

    View Slide

  79. a {
    color: red;
    }
    TEXT II

    View Slide

  80. a {
    color: rgb(244, 67, 54);
    }
    TEXT II

    View Slide

  81. a {
    color: #F44336;
    }
    TEXT II

    View Slide

  82. EX 5

    View Slide

  83. 1. Make the paragraphs inside .info italic.
    2. Make the heading inside .content underlined
    3. Have the anchors inside the list turn #0288D1. Remove their underline.

    When hovered turn them #29B6F6.
    EX 5

    View Slide

  84. .info p {
    font-style: italic;
    }
    .content h1 {
    text-decoration: underline;
    }
    .content ul li a {
    color: #0288D1;
    text-decoration: none;
    }
    .content ul li a:hover {
    color: #29B6F6;
    }
    EX 5

    View Slide

  85. MARGIN

    View Slide

  86. div {
    /* So we can see the result*/
    border: 1px solid black;
    margin: 10px;
    }
    MARGIN

    View Slide

  87. MARGIN

    View Slide

  88. div {
    border: 1px solid black;
    margin: 10px 20px;
    }
    MARGIN

    View Slide

  89. div {
    border: 1px solid black;
    margin: 10px 20px 5px 15px;
    }
    MARGIN

    View Slide

  90. div {
    border: 1px solid black;
    margin-top: 10px;
    /* ... */
    }
    MARGIN

    View Slide

  91. div {
    border: 1px solid black;
    margin: 10px;
    padding: 10px;
    }
    PADDING

    View Slide

  92. PADDING

    View Slide

  93. div {
    width: 30%;
    display: inline-block;
    }
    Display

    View Slide

  94. Display

    View Slide

  95. EX 6

    View Slide

  96. 1. Put the .info div inline, with a width of 250px.

    Vertical margin should be 20px and horizontal should be 10px.
    2. Do the same for the .content div but don’t limit its width.
    EX 6

    View Slide

  97. 1. Put the .info div inline, with a width of 250px.

    Vertical margin should be 20px and horizontal should be 10px.
    2. Do the same for the .content div but don’t limit its width.
    .info {
    display: inline-block;
    margin: 10px 20px;
    width: 250px;
    }
    .content {
    display: inline-block;
    margin: 10px 20px;
    }
    EX 6

    View Slide

  98. OTHER TAGS
    .content {
    display: inline-block;
    margin: 10px 20px;
    }

    View Slide

  99. .content {
    display: inline-block;
    margin: 10px 20px;
    vertical-align: top;
    }
    OTHER TAGS

    View Slide

  100. OTHER TAGS

    View Slide

  101. .content ul {
    list-style-type: none;
    }
    OTHER TAGS

    View Slide

  102. OTHER TAGS

    View Slide

  103. EX 7

    View Slide

  104. 1. Wrap the current content of the body inside a div.
    2. Add a div before the newly created one.

    Keep it empty and add a class of hero-container.
    3. Add a width of 100%, height of 250px and separate it from the other div.

    The distance should be 25px.
    EX 7

    View Slide







  105. .hero-container {
    width: 100%;
    height: 250px;
    margin-bottom: 25px;
    }
    EX 7

    View Slide

  106. BACKGROUND
    .hero-container {
    background-color: #333333;
    }

    View Slide

  107. .hero-container {
    background-image: url(../img/hero.png);
    }
    We are telling the CSS file where to look for the image
    Don’t forget to create this directory and file
    BACKGROUND

    View Slide

  108. BACKGROUND

    View Slide

  109. .hero-container {
    background-size: cover;
    background-position: center;
    }
    BACKGROUND

    View Slide

  110. BACKGROUND

    View Slide

  111. Programming
    wat the f*ck!?

    View Slide