2018-09-30 23:01:58 +01:00
---
id: bad87fee1348bd8aedf06756
title: Override Class Declarations by Styling ID Attributes
challengeType: 0
videoUrl: 'https://scrimba.com/c/cRkpDhB'
2019-07-31 11:32:23 -07:00
forumTopicId: 18251
2021-01-13 03:31:00 +01:00
dashedName: override-class-declarations-by-styling-id-attributes
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
We just proved that browsers read CSS from top to bottom in order of their declaration. That means that, in the event of a conflict, the browser will use whichever CSS declaration came last. Notice that if we even had put `blue-text` before `pink-text` in our `h1` element's classes, it would still look at the declaration order and not the order of their use!
2018-09-30 23:01:58 +01:00
But we're not done yet. There are other ways that you can override CSS. Do you remember id attributes?
2020-11-27 19:02:05 +01:00
Let's override your `pink-text` and `blue-text` classes, and make your `h1` element orange, by giving the `h1` element an id and then styling that id.
# --instructions--
Give your `h1` element the `id` attribute of `orange-text` . Remember, id styles look like this:
`<h1 id="orange-text">`
Leave the `blue-text` and `pink-text` classes on your `h1` element.
Create a CSS declaration for your `orange-text` id in your `style` element. Here's an example of what this looks like:
2019-05-14 01:11:58 -07:00
```css
#brown-text {
color: brown;
}
```
2020-11-27 19:02:05 +01:00
**Note:** It doesn't matter whether you declare this CSS above or below pink-text class, since id attribute will always take precedence.
# --hints--
Your `h1` element should have the class `pink-text` .
```js
assert($('h1').hasClass('pink-text'));
```
Your `h1` element should have the class `blue-text` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('h1').hasClass('blue-text'));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
Your `h1` element should have the id of `orange-text` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('h1').attr('id') === 'orange-text');
```
There should be only one `h1` element.
```js
assert($('h1').length === 1);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your `orange-text` id should have a CSS declaration.
```js
assert(code.match(/#orange -text\s*{/gi));
```
Your `h1` should not have any `style` attributes.
```js
assert(!code.match(/< h1. * style . * > /gi));
```
Your `h1` element should be orange.
```js
assert($('h1').css('color') === 'rgb(255, 165, 0)');
```
# --seed--
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
< style >
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
< / style >
< h1 class = "pink-text blue-text" > Hello World!< / h1 >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-04-22 01:57:43 -04:00
```html
< style >
body {
background-color: black;
font-family: monospace;
color: green;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
#orange -text {
color: orange;
}
< / style >
< h1 id = "orange-text" class = "pink-text blue-text" > Hello World!< / h1 >
2018-09-30 23:01:58 +01:00
```