1/1/1970
Cascading Style Sheet(CSS): it is used to define styles for your web pages, including the design, layout and variations in display for different devices and screen sizes.
Syntax:
selector { property1:value1; property2: value2; ...}
/* selector Declaration Declaration*/
h1 {color:blue; font-size:12px;}
/* ^ ^ ^ ^
property value property value
*/<p> tag -> p selectorid=para -> #para1 selectorclass-"center" -> .center selector* Select all elementsCombinations of Selectors:
<p> & class="center" -> p.center {...}p, #para, .center {...}Note:
<p class="center large"></p> : styled according to two class center & large<head>
<link rel="stylesheet" href="style.css">
</head>/*style.css*/
body { background-color: lightblue;}
h1 { color: navy; margin-left: 20px;}<head>
<style>
body { background-color: lightblue;}
h1 { color: navy; margin-left: 20px;}
</style>
</head><h1 style="color:blue;text-align:center;">Title</h1>
<p style="color:red;">This is a paragraph.</p>Note:
value and the unit 20 px ❌ 20px ✅Inline > External/Internal > Browser defaultexternal/Internal style defined after other internal/external the last read style sheet will be used.You can use comment inside /**/ anywhere in CSS Style region
p { color: /*this is a
multiple line
comment*/ blue; }
Properties : Text Color (color) , Background Color, Border Color
Value Types : color names, or RGB, HEX, HSL, RGBA, HSLA values.
{
color, background-color, border-color :
/* Using Color Name*/
Red, Green, Blue, Yellow, Orange, gray
LightGray, darkgreen DarkGreen, Tomato DodgerBlue,
MediumSeaGreen, SlateBlue,
/* Using RGB Values */ rgb(255, 99, 71)
/* Using HEX Values */ #ff6347,
/* Using HSL Values */ hsl(9, 100%, 64%),
/* Using RGBA Values */ rgba(255, 99, 71, 0.5)
/* Using HSLA Values */ hsla(9, 100%, 64%, 0.5);
}
/* Note: This is for learning purposes, commas are not used in this way */RGB Color Concept:
RGB(0,0,0) -> BlackRGB(225, 225, 225) -> WhiteR=G=B<225 -> Gray shadesA) for transparency -> 0-> fully transparent 1 no transparencyHSL Color Concept:
A) for transparency -> 0-> fully transparent 1 no transparencyHEX Color Concept:
#rrggbb -> rr(Red) + gg(Green) + bb (Blue)0.....9, a, .....f#000000 -> Black#ffffff -> White#fc9 -> #ffcc99Note:
multiple selectors or multiple values in shorthand properties, but **do not use commas when specifying a single color value for properties like color, background-color, etc.;) are used to separate CSS declarations within a rule set and to terminate the last declarationselectors (dIv) , property (coLor) , and values (rEd) , except in specific cases
.class, #id are case-sensitivefont-family or content: "Text" can be case-sensitive depending on the specific use.Opacity property Add transparency to the element like Background, text, images, and all of its child elements inherit the same transparency.
{
opacity:
0.3 , 0 /* 0 to 1*/
}Background Color:
{ background-color: lightblue, red, #f00000, rgba(255,0,0) #abc, green; }Background Image Properties:
{
background-image:
url("paper.gif"), url("gradient_bg.png");
background-repeat: /* repeats an image */
repeat-x, no-repeat, repeat-y;
background-attachment: /*background image scroll/fixed */
fixed, scroll;
background-position: /* position an image */
right top, down left;Background Shorthand:
{ background: #ffffff url("img_tree.png") no-repeat right top; }
/* Order: color > image > repeat > attachment > position */More Background Properties
{
background-blend-mode
background-clip
background-size
background-origin
background-position
background-position-x
background-position-y
}Shorthand Notes:
solid is the style, Tomato is the color, and 2px is the width.Border Specific Properties
{
border-style :
dotted, dashed, solid, double, groove, ridge, inset, outset, none, hidden,
dotted solid double; /* dotted top, solid left-right, double bottom*/
border-width :
5px, 2cm, 2pt, 2em, medium, thick, /*top-bottom-left-right*/
5px 20px, /* 5px top-bottom, 20px left-right */
25px 10px 4px 35px; /* 25px top, 10px right, 4px bottom and 35px left */
border-color :
#ff0000,/* redtop-bottom-left-right*/
red green blue yellow; /* red top, green right, blue bottom and yellow left */
}Border Shorthand
{ border: 5px solid red}
/* Order: width > style(required) > color */Border Specific Side Style
{
border-bottom /* Shorthand Property on bottom */
border-top-color /* color on top */
border-left-style /* stle on left */
border-right-width /*width on right*/
}More Border Properties:
/* Cannot be applied on specific side */
{ border-radius : 5px }Border 4 Sides -> Top + Bottom + Left + Right
Margins are used to create space around elements, outside of any defined borders.
{
margin:
25px 50px, /*Top, right, bottom, left*/
auto, /* horizontally center the element within its container.*/
inherit; /* Inherit from its parent */
} Margin on Specific Side
{
margin-top: 100px;
margin-bottom: 30%;
margin-right: 150pt;
margin-left: 80cm;
}Margin Collapse Note:
Padding is used to create space around an element's content, inside of any defined borders.
{
margin:
25px 50px, /*Top, right, bottom, left*/
auto, /* horizontally center the element within its container.*/
inherit; /* Inherit from its parent */
} Padding on Specific Side
/* Same as Margin*/
{
padding-top: 50px;
padding-right: 30%;
padding-bottom: 50em;
padding-left: 80pt;
}Note:
padding, border and margin are added to that element will be added to the total width of the element.padding/border, make box-sizing: content-box;(default) to box-sizing: border-box;padding done ✅
The total size of an element consists of:
Content: The actual content area (e.g., text, images).
Padding: Space between the content and the border.
Border: The thickness of the border.
Margin: Space outside the border.
box-sizing:content-box: Total size = content + padding + border + margin. (default)
box-sizing:border-box: Total size = content (include border, padding) + margin, (Independent of border and padding)
Properties Grouping
property-side-attributebackground,margin, paddingbordercolor, style, opacitytop, right, bottom, leftUnits in CSS
px, cm.%, em, rem, vw, vh.em or rem for scaling fonts consistently.