What is CSS
● CSS stands for Cascading Style Sheets
● If HTML is the structure of the house then CSS is the look and feel of the house
● It’s the language to make our web pages presentable
● Designed to make style sheets for web
● Now let’s try to break the acronym: Cascading: Falling of Styles Style: Adding designs/Styling our HTML tags Sheets: Writing our style in different documents
Basic Structure Selector
{ Property1 : value; Property2 : value; Property3 : value; }
● Selector: selects the element you want to target
● There are few basic selectors like tags, id’s, and classes
● All forms this key - value pair
● Keys : properties(attributes) like color, font-size, background, width, height,etc
● Value : values associated with these properties
● Always remains same whether we apply internal or external styling
Comments
don’t render on the browser
● Helps to understand our code better and makes it readable.
● Helps to debugging our code
● Two ways to comment:
○ Single line
○ Multiple line Comments
Different ways to Write CSS
● There are 3 ways to write Css in our HTML file.
○ Inline Css
○ Internal Css
○ External Css
● Priority order
○ Inline > Internal > External
Inline CSS
● Before Css this was the only way to apply styles
● Not an efficient way to write as it has lot a redundancy
● Self contained
● Uniquely applied on each element
● Idea of separation of concerns was lost
Internal CSS
● With the help of style tag we can apply styles within the HTML file
● Redundancy is removed
● But idea of separation of concerns still lost
● Uniquely applied on single document
● Example: < style>
h1{ color:red; }
External CSS
● With the help of tag in head tag we can apply styles
● Reference is added
● File saved with .css extension
● Redundancy is removed
● Idea of separation of concerns is maintained
● Uniquely applied on each document
● Example:
h1{ color:red; //.css file }
CSS Selectors
Element Selector
ID Selector
Hi
We selected id and then changed the color property i.e text color to red. Now whatever is written in this tag (content) will have the text color as redClass Selector
● Class attribute is used to select HTML element
● Used to target specific class of element
● How we do it .group { Color: red; }
Universal Selector
● Wild card character
● Used to target specific all the elements
● How we do it * { Color: red; }
Group Selector
Descendant Combinator Selector
Child Combinator Selector
Pseudo-class Selector
CSS Color
● There are different colouring schemes in CSS
● 2 widely used techniques are as follows
○ RGB
■ This starts with rgb and takes 3 parameter
■ 3 parameter basically corresponds to red, green and blue
■ Value of each parameter may vary from 0 to 255.
■ Eg: rgb(255,0,0); means color red
○ HEX
■ Hex code starts with # and comprises of 6 numbers which is further divided into 3 sets
■ Sets basically corresponds to Red, Green and Blue
■ A single set value can vary from 00 to ff
CSS Background
● There are different ways by which CSS can have effect on HTML elements
● Few of them are as follows:
○ Color - used to set the color of the background
○ Repeat - used to determine if image has to repeat or not and if it is repeating then how it should do that
○ Image - used to set image as the background
○ Position - used to determine the position of the image
○ Attachment - It basically helps in controlling the mechanism of scrolling
CSS Background
CSS Border
CSS Border
Box Model
Commentaires
Enregistrer un commentaire
Merci pour ton message 🙂
Connectez-vous pour laisser un commentaire