CSS Selectors: Let's talk basics
Tags: codenewbie, tutorial, webdev, css
Published: 2020-08-05 13:08:12

#<u>Introduction<u>#
<br>
{% twitter 1289593820770758656 %}


Note: This is for <b>absolute beginners<b> 

#### I dont know how many times I have found myself googling 'CSS selectors' and even now, I still find myself mixing up how to target CLASSES and ID's with selectors when using CSS, So lets glance over the basic ones, most commonly used in the world of CSS styling.###
Upon posting the above tweet, I found many others agreeing, so I wanted to talk about something that seems to confuse even the most confident of developers.
<br>
####Before you read on, here is a mini list of terms you will come across in this article.####

* <u> `Selectors` <u>

These are patterns that we can use, to select the element we want to style.

* <u> `Element` <u>

This selects all HTML elements based on It's <i>element<i> name EG Div, Paragraph, header etc.

* <u> `Class` <u>

A class element uses a specific class that we are able to target, and ultimately style EG: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9fjwdgd10a3vcwdy9pd7.png)

* <u> `ID` <u>

This selector uses the ID attribute of a HTML element to target a specific element. EG
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jck3p47ev0tljjavobe9.png)

* <u> `Cascading Style Sheet` <u>

Also known as CSS, describes how HTML elements should be displayed on a website or other media. It can control and alter multiple layouts at once, saving a lot of work and time In the process.  

<br>


<u>Where can we use selectors?<u>

Selectors are used to target specific ID's or classes; they tell the web browser which HTML elements should be selected, to have the given CSS rule/value applied to them. 
We can use 2 specific selectors ( ‘.’ & ‘#’) to change the CSS of an element, by targeting them. 
<br>
<u>Types of Selector:<u>

(.) - Period or full stop; This targets a `class`, and will apply any modified changes to that particular element.
<br>
(#) - Hash sign; These are used to target a specific element with a unique ID.
<br>
Note: Its important to get these the correct way round when you are targeting elements, because if not, the changes made in the stylesheet will not apply. (Trust me, Its ok if you get these mixed up to begin with, It has taken me some time to get it right myself!)
Selectors should be displayed like this: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e09nxq59mxt6v24xkn05.png)
<br>
Additional selectors can be used to change the appearance of various rules created.
<br>
Some of these include:

<u>`Asterix:`<u>

The Asterix selector will select every HTML element on the page and style them EG: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hg3hivctr4e5audwoiie.png)

<u>`Grouping Selector:`<u>

As the name suggests, the grouping selector changes the style of particular elements (Div, Paragraph,Header etc..) that have been selected specifically by the user.
EG:    
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/efdvtrpjyl5lcmx9v4kk.png)

Hopefully this mini-article will help grasp some of the basics reagrding CSS selectors.

I’m planning to go more in depth about @media & targeting paragraphs in another article; So watch this space! 😃