CSS Selector Basics - Element, Class, and ID

  Рет қаралды 3,223

Craig A. Bourne

Craig A. Bourne

Күн бұрын

► Selectors allow us to target elements and apply styles. We can select a large number of similar elements, or be more specific and construct rules that apply in very narrow circumstances.
In this video, we will focus on three common selector types. These are:
- class selectors
- ID selectors
- element selectors
A class can be used as many times on a page as we like, as opposed to an ID which is used just once to uniquely identify an element, say for example a page wrapper, a navbar, or a footer. Each of which will only appear once on any given webpage.
We select IDs by referencing them by their name preceded by a hash or octothorpe (#), and we select classes by using a full stop (.) preceding the name of the class. These will select elements that have matching ID or class attributes added to their opening tags.
When selecting an HTML element we simply need to reference the element by its name (h2, div, p, nav) without anything additional added to the HTML.
► Font stack to paste in, in CodePen: font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
► Timestamps:
0:00 Start
1:10 CSS Syntax & the general rule
2:08 Getting the project files
2:48 Live Server
3:20 The three kinds of selectors we’ll learn in this video
4:00 The element selector
5:20 Selector declaration blocks can contain multiple style declarations
5:54 Inheritance
6:41 Applying a font to body, which is inherited by descendant elements
7:07 Font stacks
9:06 More font props
9:38 Space separated property values
11:16 Shorthand properties
11:53 Inspecting styles in DevTools
13:18 Grouping selectors
14:41 Summary of element selectors
15:10 ID selectors
20:45 What IDs are used for
21:17 Class selectors
24:02 Adding a class to multiple elements
25:29 Adding classes to body & html elements in CodePen
26:21 Multiple classes on a single element
28:22 We cannot use more than one ID on a single element
29:40 Grouping mixed selector types
29:58 Summary
► Get the code:
GitHub Repo: github.com/craigabourne/css-s...
CodePen Start: codepen.io/craigabourne/pen/Q...
CodePen End: codepen.io/craigabourne/pen/J...
► Links used in the video ( & other resources):
Live Server: marketplace.visualstudio.com/...
Shorthand font: developer.mozilla.org/en-US/d...
Shorthand properties: developer.mozilla.org/en-US/d...
MDN Selectors: developer.mozilla.org/en-US/d...
CSS Tricks - How Selectors Work: css-tricks.com/how-css-select...
► Inheritance video link: • Understanding Inherita...
► Other types of CSS Selectors:
Child & Descendant Selectors: • CSS Child and Descenda...
Sibling Selectors: • Adjacent and General S...
Universal & Attribute Selectors: • Universal and Attribut...
Pseudo-classes: • How to Use CSS Pseudo-...
Pseudo-elements: • How to Manipulate Cont...
► This video is part of the CSS for Absolute Beginners playlist: • CSS for Absolute Begin...
► Social Media:
/ craigabourne
/ craigabourne
► Code & Projects:
github.com/craigabourne
codepen.io/craigabourne

Пікірлер: 24
@craigabourne
@craigabourne 3 жыл бұрын
Learn CSS: kzbin.info/aero/PL4cTxE4s2XIYwGURywyDlkfmhmRC5FaUR
@janelleschuh3263
@janelleschuh3263 2 жыл бұрын
Happy i "selected" this amazing video.
@craigabourne
@craigabourne 2 жыл бұрын
ba dum tss! 😂
@clinthoon
@clinthoon 2 жыл бұрын
Wish I could give two thumbs up. Superb! 👍👍
@craigabourne
@craigabourne 2 жыл бұрын
Thank you so much 😀
@shansutherland
@shansutherland 3 жыл бұрын
These selector videos are super helpful. You are a great teacher
@craigabourne
@craigabourne 3 жыл бұрын
Thank you! I appreciate the kind words
@jovanstrickland
@jovanstrickland 2 жыл бұрын
thanks brother youre layin it all out for us
@craigabourne
@craigabourne 2 жыл бұрын
Glad to help
@manendarpverma5252
@manendarpverma5252 2 жыл бұрын
Thank you soo much!, I been looking for something like this for a while now and you explained it really well. You just got yourself a sub :))
@craigabourne
@craigabourne 2 жыл бұрын
Awesome, thank you!
@pranavguly
@pranavguly 2 жыл бұрын
Thanks! Another superb video. Cant wait to watching the rest of the videos on selectors
@craigabourne
@craigabourne 2 жыл бұрын
Glad you like them!
@Naz-yi9bs
@Naz-yi9bs 3 жыл бұрын
Amazing explanation! I'll be watching the "Developer Tools" playlist until the next video release in this series!
@craigabourne
@craigabourne 3 жыл бұрын
Awesome! Thanks Naz. Appreciate the kind words 👍 Making the videos as quick as I can. Wish I could go faster!
@jensdan4489
@jensdan4489 Жыл бұрын
This channel is soo good
@craigabourne
@craigabourne Жыл бұрын
Thank you! Appreciate it!
@dobrilofotis
@dobrilofotis Жыл бұрын
100th like congrats!
@craigabourne
@craigabourne Жыл бұрын
🎉
@sophiawokoma3711
@sophiawokoma3711 2 жыл бұрын
so can you still apply two ids to one html element but just not via the the space separated list method , e.g Heading ?
@craigabourne
@craigabourne 2 жыл бұрын
Hi Sophie! No, you can only have one ID on one HTML element. Since ids are unique only one is needed to uniquely identify that specific tag. If you try to add two separate id attributes to an HTML element, the browser will ignore the second added and only recognise the first id attribute in the opening tag.
@laflamenca7742
@laflamenca7742 Жыл бұрын
One question, Did you separate the classes uppercase and big text just for the example? Or why you didn't create only one class in css like upper case big text??
@ovidiu2394
@ovidiu2394 2 жыл бұрын
springgreen
@craigabourne
@craigabourne 2 жыл бұрын
😂 Every video pretty much
CSS Child and Descendant Selectors
13:13
Craig A. Bourne
Рет қаралды 2,6 М.
How to Use CSS Pseudo-Classes
28:59
Craig A. Bourne
Рет қаралды 1,7 М.
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 35 МЛН
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 33 МЛН
Combining and Chaining CSS Selectors
10:47
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 28 М.
Adjacent and General Sibling Selectors in CSS
16:45
Craig A. Bourne
Рет қаралды 2,2 М.
Learn Sass In 20 Minutes | Sass Crash Course
19:42
developedbyed
Рет қаралды 926 М.
Why didn't the Angular team just use RxJS instead of Signals?
8:15
Joshua Morony
Рет қаралды 87 М.
CSS Specificity
23:06
Craig A. Bourne
Рет қаралды 2,1 М.
Mastering the CSS Box Model
21:16
Craig A. Bourne
Рет қаралды 3,9 М.
Universal and Attribute Selectors in CSS
17:53
Craig A. Bourne
Рет қаралды 1,6 М.
Is HTMX a Joke??
32:15
Syntax
Рет қаралды 17 М.
Understanding Inheritance in CSS
12:37
Craig A. Bourne
Рет қаралды 1,7 М.
Secret Wireless charger 😱 #shorts
0:28
Mr DegrEE
Рет қаралды 2 МЛН
CY Superb Earphone 👌 For Smartphone Handset
0:42
Tech Official
Рет қаралды 825 М.