text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
So color colon blue, for example, followed by a semicolon
2,395.67
4.42
will change the color of this h1 element to blue.
2,400.09
3.11
And my text editor is automatically showing me
2,403.2
1.92
a little square that shows me what this color blue is actually
2,405.12
3.03
going to look like.
2,408.15
0.87
This isn't part of the text.
2,409.02
1.17
It's just my text editor being helpful so
2,410.19
2.07
that I can see in advance as I'm writing this code what the color is actually
2,412.26
3.75
going to look like.
2,416.01
2.02
So now if I open up style.html, here's what I see.
2,418.03
4.64
Instead of a black heading at the top, we've changed the color to blue.
2,422.67
3.84
And there are many other built-in colors that
2,426.51
2.16
exist within HTML that we can use in order to change
2,428.67
2.79
the color to whatever we want.
2,431.46
1.46
If instead of blue, I said I want the color to be red,
2,432.92
2.42
for instance, I can refresh the page.
2,435.34
2.34
And now, the heading is red.
2,437.68
1.19
And there are many other colors.
2,438.87
1.33
I can change the color to like spring green, for instance.
2,440.2
2.69
And that's going to be a particular shade
2,442.89
1.71
of green that displays just like this.
2,444.6
3.03
And so now, we have the ability to add various different style
2,447.63
3.27
properties to individual elements.
2,450.9
2.16
I can say take this heading and change its style
2,453.06
2.73
so that the color instead of being black is going to show up as blue instead.
2,455.79
4.93
And if I want to add multiple CSS properties to the same HTML element,
2,460.72
4.01
I can do that as well.
2,464.73
1.53
Here in the style attribute, I can say that in addition
2,466.26
2.52
to saying that the color is blue, I'd like to give a second CSS
2,468.78
3.66
property to this element.
2,472.44
1.53
I'd like to say that the text align property should be center, for example.
2,473.97
7.29
The text align property controls, as you might imagine,
2,481.26
3.3
how a particular HTML element has its text aligned.
2,484.56
2.82
Is it all the way on the left, all the way on the right, or centered?
2,487.38
3.02
And if I change the text align property to have a value of center,
2,490.4
4.39
well, then now, when I refresh this page, I see that Welcome to my web page
2,494.79
4.7
is now both blue, and it's centered.
2,499.49
2.38
I've changed the color, and I've changed the alignment
2,501.87
3.12
of this particular element.
2,504.99
2.37
And HTML elements don't need to just be styled directly.
2,507.36
3.48
They can also get their style information from parent elements.
2,510.84
4.66
So if you recall again that DOM structure, where
2,515.5
2.75
we have an HTML element inside of which is this body element
2,518.25
4.02
and inside of the body element is this h1 element and this text,
2,522.27
4.38
you can imagine if we wanted this styling
2,526.65
2.22
to apply not just to this heading, but also to the Hello World text,
2,528.87
4.47
I could move the styling information, move this style attribute,
2,533.34
3.66
change it from the h1 and escalating it to this body.
2,537
4.11
And if I move the style to the body, then everything inside of the body
2,541.11
4.05
is going to be styled in that way.
2,545.16
2.38
So let's now take a look at an example of that to see how that works.
2,547.54
3.48
If I take this style information, and I move
2,551.02
2.57
it so that instead of associating it with the h1,
2,553.59
3.36
I instead associate it with the body, then now, when I refresh the page,
2,556.95
5.27
I see that both parts of the body, both the big heading
2,562.22
2.63
at the top that says, Welcome to my web page,
2,564.85
2.16
as well as the text, Hello World, both have those CSS properties applied.
2,567.01
4.17
I've changed their color to blue.
2,571.18
1.95
And I've also changed their text alignment
2,573.13
2.13
to be centered instead of just left aligned.
2,575.26
3.6
But if I do want it to just be that heading,
2,578.86
2.19
then I can move it out and say that I just
2,581.05
2.94
want to apply the style to that one individual heading.
2,583.99
4.65
Now, one thing that we might imagine might become a problem over time
2,588.64
3.53
is that imagine if I had multiple headings that I wanted
2,592.17
3.15
to style in the same way, for example.
2,595.32
2.28
Let's say I have a second heading that--
2,597.6
2.49
this is a second heading--
2,600.09
1.51
that I also want to be styled as blue and centered as well,
2,601.6
4.28
I can refresh this page and see that right now that is not the case.
2,605.88
3.01
And I don't want to make the entire page blue and centered.
2,608.89
2.64
I only want these two headings to be blue and centered.
2,611.53
3.59
So what I could do is I could just take this style code from the h1
2,615.12
4.41
and apply it to this h1 as well, so that both of my h1 elements
2,619.53
4.14
now have the exact same style code.
2,623.67
2.47
And I'll go ahead and refresh this.
2,626.14
1.46
And now, we see this is the intended behavior.
2,627.6
2.55
I have two headings, both of which are centered and both of which are blue.
2,630.15
4.23
But what we want to start to think about as we start to build web applications,
2,634.38
3.51
and especially as our web applications start to get a little bit more
2,637.89
3
sophisticated, is to think about the design
2,640.89
2.7
of how we're building our web pages and how
2,643.59
2.04
we're building our web applications.
2,645.63
1.72
And in particular, anytime we find ourselves
2,647.35
2.24
copying a lot of the same information from one place
2,649.59
3
to another, that's probably not the best design.
2,652.59
2.57
And you should start to think about how might you
2,655.16
2.05
design this a little bit better.
2,657.21
1.9
It's not great design, one, just because there's
2,659.11
2
some redundancy that probably doesn't need to be there,
2,661.11
2.67
but also because it makes the page a little bit more
2,663.78
2.43
difficult to change and add a little more difficult to update.
2,666.21
2.73
If I instead want to change both of these headings
2,668.94
2.31
to be red instead of blue, then all of a sudden,
2,671.25
2.73
I need to change my code in two places.
2,673.98
2.89
I need to change the style attribute on this first heading up here.
2,676.87
3.83
And I also need to change the style attribute
2,680.7
2.4
on the second heading down there.
2,683.1
2.67
What I'd like to do is to somehow just be
2,685.77
2.04
able to write the style code once and then have
2,687.81
2.82