< Return to Video

CSS grouping elements

  • 0:00 - 0:02
    So far we've seen how you can
  • 0:02 - 0:04
    use CSS to style your text,
  • 0:04 - 0:06
    but we can also use CSS to completely
  • 0:06 - 0:08
    change the layout of our page.
  • 0:08 - 0:09
    That means we can move things around,
  • 0:09 - 0:10
    change the size,
  • 0:10 - 0:12
    even put things on top of each other.
  • 0:12 - 0:14
    But what are the things
  • 0:14 - 0:14
    we want to move around?
  • 0:14 - 0:16
    Sometimes they're elements
  • 0:16 - 0:17
    that we've already made,
  • 0:17 - 0:19
    like a certain paragraph,
  • 0:19 - 0:21
    or a certain heading.
  • 0:21 - 0:22
    But often times,
  • 0:22 - 0:25
    they're a group of elements that we've made,
  • 0:25 - 0:27
    like a selection of text,
  • 0:27 - 0:30
    or a heading and a few paragraphs.
  • 0:32 - 0:33
    In order to move them
  • 0:33 - 0:34
    around together as a unit,
  • 0:34 - 0:37
    we need to introduce two new HTML tags.
  • 0:37 - 0:39
    Which we call the grouping elements.
  • 0:39 - 0:41
    We didn't talk about them before CSS,
  • 0:41 - 0:43
    because they're only useful
  • 0:43 - 0:44
    when combined with CSS.
  • 0:44 - 0:47
    They have no semantic meaning to the browser.
  • 0:47 - 0:49
    The first tag, is the tag,
  • 0:50 - 0:52
    and it's what we use for grouping
  • 0:52 - 0:53
    a selection of text.
  • 0:53 - 0:54
    Let's say we want a colour,
  • 0:54 - 0:57
    that's word "Love Red".
  • 0:57 - 0:59
    And we just want to colour the word,
  • 0:59 - 1:00
    not the rest of the heading.
  • 1:00 - 1:02
    We'll put our cursor before "Love",
  • 1:02 - 1:06
    type the start tag for .
  • 1:06 - 1:11
    Put it after, type the end tag, okay.
  • 1:11 - 1:12
    Now we want to style this
  • 1:12 - 1:13
    of characters.
  • 1:13 - 1:15
    We could make a rule to colour all s
  • 1:15 - 1:16
    on the page,
  • 1:16 - 1:19
    but we may not want them all to be red.
  • 1:19 - 1:20
    Let's give the a
  • 1:20 - 1:22
    class of "lovey-dovey",
  • 1:25 - 1:29
    and add a rule just for elements that
  • 1:29 - 1:30
    have the class "lovey-dovey".
  • 1:30 - 1:34
    So, .lovey-dovey, color: red.
  • 1:35 - 1:37
    Look at how lovey dovey that text is now!
  • 1:38 - 1:40
    So s are good for grouping
  • 1:40 - 1:42
    selections of text, how do we group a
  • 1:42 - 1:43
    bunch of elements together?
  • 1:44 - 1:45
    That's where the tag comes in.
  • 1:46 - 1:47
    Let's say we want to group
  • 1:47 - 1:48
    this bottom section.
  • 1:48 - 1:49
    The official info header, and
  • 1:49 - 1:51
    the paragraphs and picture below it.
  • 1:52 - 1:53
    To do that,
  • 1:53 - 1:58
    I'll put my cursor before the h3 and do
  • 1:58 - 1:59
    the start tag for .
  • 2:00 - 2:02
    And then go down to the final paragraph,
  • 2:03 - 2:05
    and right the end tag for .
  • 2:05 - 2:08
    We have a , now we need to style it.
  • 2:09 - 2:10
    To style the ,
  • 2:10 - 2:11
    I'm going to give it an ID.
  • 2:11 - 2:14
    "official-info".
  • 2:15 - 2:16
    Then add a rule for it up here.
  • 2:16 - 2:21
    So #official-info, and background.
  • 2:22 - 2:24
    Let's make it a nice grey.
  • 2:24 - 2:27
    Let's pick out... this... That's good.
  • 2:27 - 2:29
    So now you can see the has become
  • 2:29 - 2:31
    a grey box containing all of the elements
  • 2:31 - 2:32
    inside of it.
  • 2:32 - 2:34
    And it's different from if we give each of
  • 2:34 - 2:36
    them a grey background separately.
  • 2:36 - 2:38
    If we did that, there would be a space in
  • 2:38 - 2:39
    between them that wouldn't go gray.
  • 2:40 - 2:41
    We have to make a ,
  • 2:41 - 2:43
    if we want a box around everything.
  • 2:45 - 2:46
    You can think of ,
  • 2:46 - 2:48
    as being for grouping text.
  • 2:48 - 2:51
    And you can think of ,
  • 2:51 - 2:52
    for grouping elements.
  • 2:52 - 2:55
    But there's another way to distinguish them as well.
  • 2:55 - 2:57
    You see there are two types
  • 2:57 - 2:58
    of elements in the CSS world.
  • 2:58 - 3:00
    Inline and block.
  • 3:00 - 3:03
    An inline element does not have a new line after it.
  • 3:04 - 3:07
    Like if you make a multiple of them they will all be on the same line.
  • 3:07 - 3:09
    A few examples we have talked about are
  • 3:09 - 3:12
    a and image.
  • 3:12 - 3:13
    And you can see with this image,
  • 3:13 - 3:16
    how it just runs into the text next to it.
  • 3:17 - 3:18
    There's no new line after it.
  • 3:19 - 3:22
    A block element does have a line after it,
  • 3:22 - 3:25
    and that is what most HTML tags create.
  • 3:25 - 3:27
    Look at all the examples on this page.
  • 3:27 - 3:30
    The headings, the paragraphs, the list.
  • 3:31 - 3:34
    The browser put new lines after all of them,
  • 3:34 - 3:36
    without you needing to write a
    tag.
  • 3:37 - 3:39
    What does that have to do with ,
  • 3:39 - 3:40
    and ?
  • 3:40 - 3:43
    Well a creates an inline element,
  • 3:43 - 3:47
    and a creates a block element.
  • 3:47 - 3:49
    That means, that if you add a ,
  • 3:49 - 3:53
    and don't add any other style,
  • 3:54 - 3:56
    the browser will blockify
  • 3:56 - 3:58
    that part of the page.
  • 3:58 - 4:01
    Like that bit of text just wrapped in a ,
  • 4:01 - 4:03
    now has new lines before and after.
  • 4:03 - 4:05
    And maybe that's what you want,
  • 4:05 - 4:08
    just keep this difference in mind.
  • 4:08 - 4:09
    And keep going, because there's a lot more
  • 4:09 - 4:11
    we can do with these tags.
  • 4:11 - 4:13
    Especially the might .
  • 4:13 - 4:14
    Captioned by: 5A Jasmine :) aka JP 4B :)
Title:
CSS grouping elements
Description:

{'type': u'plain'}

Captioned by: 5A Jasmine :) aka JP 4B :)

more » « less
Video Language:
English
Duration:
04:14

English subtitles

Revisions