text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
have a class of Baz. | 4,306.33 | 2.71 |
So here, I can now say, take all
of the elements with a class of Baz | 4,309.04 | 3.83 |
and go ahead and give
those a color of blue. | 4,312.87 | 5.03 |
So now, I have two h1s
that belong to class Baz. | 4,317.9 | 3.65 |
The other h1 does not. | 4,321.55 | 1.78 |
And I've styled only the
things that are of class Baz, | 4,323.33 | 3.32 |
such that now when I go back to the
page and refresh the page, my first two | 4,326.65 | 3.6 |
headings, those do get styled as blue. | 4,330.25 | 2.48 |
But the third heading
does not, because I've | 4,332.73 | 1.84 |
applied a class to these two
elements that does not get | 4,334.57 | 2.7 |
applied to this third element there. | 4,337.27 | 2.95 |
So oftentimes, it can
be very helpful if you | 4,340.22 | 1.97 |
have to start to design
larger web pages where | 4,342.19 | 2.01 |
you have multiple different
elements, some of which | 4,344.2 | 2.31 |
might be styled in some ways and other
elements that might be styled similarly | 4,346.51 | 3.57 |
to one another, you can add IDs
and classes to your HTML elements | 4,350.08 | 4.71 |
just to clean up the way
that you write your CSS, | 4,354.79 | 2.34 |
to be able to very specifically
pinpoint one element that you | 4,357.13 | 2.97 |
want to apply a style to or to apply
styling to the entire class of elements | 4,360.1 | 5.16 |
as well. | 4,365.26 | 1.59 |
Now, one tricky thing
you might imagine now | 4,366.85 | 2.46 |
is that now we have multiple ways of
referencing the exact same element. | 4,369.31 | 6.03 |
So, for example, if
you imagine that I just | 4,375.34 | 2.13 |
had a single h1, which had an ID
of Foo, for example, that I've | 4,377.47 | 4.95 |
named Foo, what would happen if, for
instance, I said all of the h1s I | 4,382.42 | 5.27 |
will like those to be colored red, and
all of the elements with an ID of Foo, | 4,387.69 | 4.72 |
or the only element with an ID of Foo,
I would like that to be colored blue? | 4,392.41 | 4.8 |
What might happen then? | 4,397.21 | 0.96 |
These would seem to be
conflicting, where now suddenly we | 4,398.17 | 2.85 |
have an h1 style tag that is saying
I should style h1s in this way, | 4,401.02 | 6.09 |
but I should style element
Foo in another way. | 4,407.11 | 2.74 |
So what happens if I have an h1 whose ID
is Foo, how do I choose to style that? | 4,409.85 | 5.42 |
And in order to deal with
that we have to start | 4,415.27 | 2.07 |
to deal with the CSS problem of
specificity, of what happens when | 4,417.34 | 3.84 |
I have multiple different CSS selectors
that could apply to the exact same HTML | 4,421.18 | 5.82 |
element? | 4,427 | 0.99 |
And this often happens when we start
to add IDs and classes to our elements | 4,427.99 | 5.67 |
as well. | 4,433.66 | 1.24 |
So when we deal with specificity,
specificity goes in a particular order. | 4,434.9 | 3.97 |
There's an order of
precedence that we can | 4,438.87 | 1.93 |
follow for determining what
style should ultimately | 4,440.8 | 3.12 |
be applied to any particular element. | 4,443.92 | 2.83 |
The first, most powerful-- | 4,446.75 | 1.85 |
most specific way of referencing an
element is inline styling, literally | 4,448.6 | 4.2 |
adding a style equals
attribute to our HTML elements | 4,452.8 | 3.6 |
in the way we did way
at the beginning when | 4,456.4 | 1.8 |
we were first taking a look at CSS. | 4,458.2 | 2.31 |
If we associate inline styling
with an HTML element, that's | 4,460.51 | 3.69 |
going to take precedence over any
styling that's inside the style | 4,464.2 | 3.63 |
section of our head of the web page
or inside of a separate dot CSS file, | 4,467.83 | 4.32 |
because the reasoning goes, if you
are literally putting the style | 4,472.15 | 4.38 |
code attached to the element
itself, then we probably | 4,476.53 | 3.27 |
want to apply it to that element. | 4,479.8 | 2.55 |
After that, specificity goes
in order of how precisely we | 4,482.35 | 5.37 |
are identifying an element. | 4,487.72 | 1.47 |
An ID is a unique way
to identify an element. | 4,489.19 | 2.49 |
There is only one element
with that particular ID. | 4,491.68 | 2.8 |
So if I've added style
to a particular ID, | 4,494.48 | 3.08 |
that is going to be pretty highly
valued in terms of how specific it is. | 4,497.56 | 4.14 |
Next, we look at classes. | 4,501.7 | 1.42 |
So if there's no ID
selector, we look for, | 4,503.12 | 2.63 |
did we reference the
element by its class? | 4,505.75 | 2.4 |
And if so, then that
takes next precedence. | 4,508.15 | 3.16 |
And otherwise, then we fall back
to what type of HTML element it is. | 4,511.31 | 4.16 |
Is it an h1? | 4,515.47 | 1.08 |
Is it an ordered list? | 4,516.55 | 1.35 |
Is it a table? | 4,517.9 | 1.08 |
So in short, the type
is the least specific. | 4,518.98 | 2.29 |
Class is slightly more specific. | 4,521.27 | 1.82 |
ID is more than that. | 4,523.09 | 1.42 |
And the most specificity we can provide
is by literally putting the CSS inline | 4,524.51 | 4.82 |
with the HTML element itself. | 4,529.33 | 2.56 |
So let's take a look
at an example of this. | 4,531.89 | 2.04 |
Let's look at this code, for
example, where, for instance, I | 4,533.93 | 3.62 |
have a div, whose ID is Foo, inside of
which I'm just saying the word hello. | 4,537.55 | 4.83 |
And the CSS code that I've included
here is I've said for all div, | 4,542.38 | 3.63 |
I would like to give
those a color of blue. | 4,546.01 | 2.31 |
Obviously, in that case,
there's nothing conflicting. | 4,548.32 | 2.4 |
What we're going to see is we're
going to see the word Hello. | 4,550.72 | 2.55 |
And we're going to see
the word Hello in blue. | 4,553.27 | 3.3 |
But what happens now if we add anything
with ID Foo should be colored red? | 4,556.57 | 5.1 |
Well, because ID has higher specificity
than just an individual tag, | 4,561.67 | 4.74 |
well, then next, what we're going to say
is that this Hello is going to show up | 4,566.41 | 3.3 |
is red. | 4,569.71 | 0.87 |
The ID is more specific. | 4,570.58 | 1.8 |
And so this element is going
to show up red instead. | 4,572.38 | 3.54 |
And it doesn't matter
what order these are in. | 4,575.92 | 1.92 |
It's not that the later
one takes precedence. | 4,577.84 | 1.9 |
If I were to flip these around, where
ID of Foo, color red, div color blue | 4,579.74 | 4.67 |
is in that order, it's still going
to show up as red, because this ID | 4,584.41 | 3.93 |
selector is more specific than just the
name div, which is the name of the HTML | 4,588.34 | 6.66 |
element that happens to be there. | 4,595 | 2.38 |
And so as you start to develop
more sophisticated style sheets, | 4,597.38 | 2.84 |
you might find that
some of your CSS code | 4,600.22 | 1.89 |
is going to conflict with each other. | 4,602.11 | 1.56 |
And that's where it's important to
bear in mind how these specificity | 4,603.67 | 2.87 |
rules work to know as you
add style to your elements | 4,606.54 | 3.4 |
how are they actually
going to end up showing up. | 4,609.94 | 4.06 |
Now, we've seen a
couple of CSS selectors | 4,614 | 1.83 |
now in terms of selecting a
single element, selecting an ID, | 4,615.83 | 3.54 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.