Skip to content

Commit b939b18

Browse files
committed
Create solutions.md
Adding a solutions page
1 parent 81bf363 commit b939b18

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

learn/solutions.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Task Solutions
2+
3+
Solutions for the tasks in the CSS Learn section of MDN.
4+
5+
## Attribute Selectors
6+
7+
[Task](https://developer.mozilla.org/en-US/docs/User:chrisdavidmills/CSS_Learn/CSS_Selectors/Attribute_selectors#Try_it_out)
8+
9+
Task: Target the `<a>` element with a title attribute and make the border pink (border-color: pink).
10+
11+
To select elements with a title attribute we can add `title` inside the square brackets, which will select the second link, which is the only one with a title attribute.
12+
13+
```
14+
a[title] {
15+
border-color: pink;
16+
}
17+
```
18+
19+
Target the `<a>` element with an href attribute which contains the word contact anywhere in its value and make the border orange (border-color: orange).
20+
21+
There are two things we want to match here, the href value "/contact" and also "../contact". So we need to match the string "contact" anywhere in the value using `*=`. This will select the third and fourth links.
22+
23+
```
24+
a[href*="contact"] {
25+
border-color: orange;
26+
}
27+
```
28+
29+
Target the `<a>` element with an href value starting with https and give it a green border (border-color: green).
30+
31+
Here we can look for an href value which starts with "https" and so use `^=`, this will only select the first link.
32+
33+
```
34+
a[href^="https"] {
35+
border-color: green;
36+
}
37+
```

0 commit comments

Comments
 (0)