Basis Of Css
Tags: programming, css
Published: 2021-09-08 08:52:28

#Introduction-
So Css full form is Cascading Style sheets.It is basically a document to style the webpages.Css is what gives your webpage colors and cool animations.
#Types-
There are 3 types of css-
1. Inline Css-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36xjbuhw9lu7oi950iek.png)
This type of css is injected into element using style attribute.And we have to provide attributes which we want to target inside it.Its area of scope is only one particular element.
2. Internal Css-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3b4l6vlvh6sddrk2pvk.png)
This type of css is used by using `<style>` tag.The `<style>` tag is positioned inside head tag.  Its area of scope is one html Document we can update the single document style with the help of this.
3. External Css-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oprfyyvsgaezdlqjkl24.png)
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u30zn1s9jdedupk34i8g.png) 
So basically we create an external style.css file where we create our styles and link it inside html document using the `<link>` tag.This external css scope is much wider compared to last two we can create a single style sheet for multiple html pages and just link it inside the html to generate styles.

#Box-Model-
![Box-Model](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/it0jy8tjfg65ydpzj8h2.gif)
So in css we have box model to style everything.Consider a block element as as `div` we can style it using the above properties.
Box model has following properties-
* Content-It means Content of box where all elements and images appear.
* Padding-It is an outer area around content and it is tranparent.
* Border-A border that goes around padding and content.
* Margin-A transparent area around border which seprates it from another element box-model.

##Basic Css Selectors-
1. Element Selectors-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3hops8ovtnknw36jliu.png)
Here we can directly Specify the element name and then describe its property.Then the following styles will be applied to all the elements tag with same tag.

2. Class selectors-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0dbbudbvq46bx2hctt3.png)
We can define a class in an element like this.And then target the class in style tag or any stylesheet.The class is represented using `.class-name` in css.Its specificity(effect) is greater than normal Element Selector.  

3. Id Selectors-
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4yl966d6aqzy6anwfpl3.png)
So these are basically same as class selectors but they are unique only one element inside a document can have an id. The id is represented as `#id-name` in css.There is also an additional benefit of these id selectors if we put id name in href attribute of anchor tag it will take us to where the id element in document is located when clicked.These are helpful it creating navigation across different sections in a page.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrqnso5siowk3nuyxzo4.png)

#Conclusion-
So we can effectively use css to style our webpages.Whether we use inline,internal or external to style our pages we should consider the box model and style our elements accordingly.
####P.S-For more detailed explanation and read about css properties use can visit csstricks website.And for properties and information on all tags you can use mdn as a reference.