CSS INTRODUCTION
CSS stands for Cascading Style Sheets.
It's a markup language used to apply styles for HTML.
CSS works by selecting HTML elements and applying styles to them.
Role of CSS
Content SeparatedThe primary role of CSS is to separate the content of a web page from its visual presentation.
This separation allows web developers to create more flexible and maintainable websites.
With CSS, developer can control the layout, colors, fonts, and overall visual appearance of web pages without altering the HTML structure.
Responsive Web Design
One of the most powerful aspects of CSS is its ability to create responsive designs.
With CSS, developer can make the website look great on any device; like in a desktop computer, a tablet, or a smartphone.
CSS allows developer to adjust layouts, font sizes, and other visual elements based on the screen size of the device viewing the website.
Cascading Nature
Another important feature of CSS is its cascading nature, which is where the "cascading" in its name comes from.
The styles can be inherited and overridden, allowing for a hierarchical structure of styling.
External StylesheetsCSS also supports the use of external stylesheets.
Developer can keep all their styling rules in a separate file, which can then be linked to multiple HTML pages.
This feature greatly enhances the maintainability of websites, especially larger ones.
Instead of having to change styles on each individual page, you can make changes in one CSS file that will affect all linked pages.
Basic Syntax
mySelector { myProperty: myValue; }
A CSS rule is made up of two main parts: a selector and a declaration block.
If developer want to apply the same set of styles to multiple selectors, they can create a selector list with each selector separated by a comma.
mySelector1, mySelector2, mySelector3 { myProperty1: myValue1; myProperty2: myValue2; myProperty3: myValue3; } Selector
A selector is a pattern used in CSS to identify and target specific HTML elements for styling.
Example; Type Selectors, Class Selectors, ID Selectors, Universal Selector, Attribute Selectors, and Combinator Selectors.
Declaration Block
The curly braces provided in the basic syntax are known as a declaration block.
A declaration block applies a set of styles for a given selector, or selectors.
Inside the declaration block, it will have a series of declarations.
Each declaration consists of a property and a value.
The property is the CSS identifier that specifies which feature is being styled.
The value would be the specific setting applied to that property
After each property name, developer need to place a colon, and after each value, they should have a semicolon.
TYPE OF WRITTEN CSS
Inline CSS
Inline CSS is written directly within an HTML element using the style attribute.
It applies styles to a specific element.
Inline CSS is generally used for quick, one-off styles or to override other styles for a specific element.
However, it should be avoided in most cases because it can clutter the HTML and make the code harder to maintain.
Internal CSS
Internal CSS is written within the style tags inside the head section of an HTML document.
It applies styles to the entire page and is useful when developer need to style a single document.
Internal CSS is best used when developer need to apply styles to a specific page rather than across multiple pages.
It's useful for single-page websites or when the styles don't need to be reused elsewhere.
However, there are some downsides, such as not promoting reusability across multiple pages.
Additionally, like inline CSS, it mixes HTML and CSS, making the code harder to maintain in larger projects.
External CSS
External CSS is written in a separate CSS file and linked to the HTML document using the link element in the head section.
It allows developer to style multiple pages consistently and is the preferred method in professional web development.
External CSS is ideal for large projects where you want to maintain a consistent style across multiple pages.
It promotes separation of concerns by having HTML handle the structure and CSS handle the styling, which makes the code more maintainable and scalable.
Most of the time, it's better to use external CSS to keep the styles organized and maintainable.
CSS SELECTORS
Type Selectors
Class Selectors
.myClass { myProperty: myValue; }
All class selectors must start with a dot.
ID Selectors
#myId { myProperty: myValue; }
All ID selectors must start with a hash symbol.
Universal Selector
* { myProperty: myValue; }
Attribute Selectors
mySelector[myAttribute] { myProperty: myValue; }
It is used to select elements with the specified attribute.
mySelector[myAttribute="myValue"] { myProperty: myValue; }
It is used to select elements with the specified attribute and the exact value.
mySelector[myAttribute~="myValue"] { myProperty: myValue; }
It is used to select elements with an attribute value containing a specific word.
mySelector[myAttribute|="myValue"] { myProperty: myValue; }
It selects elements with the specified attribute with the exact specified value, or the exact specified value followed by a hyphen (-).
mySelector[myAttribute^="myValue"] { myProperty: myValue; }
It matches every element whose attribute value begins with the specified value.
mySelector[myAttribute$="myValue"] { myProperty: myValue; }
It matches every element whose attribute value ends with the specified value.
mySelector[myAttribute*="myValue"] { myProperty: myValue; }
It matches every element whose attribute value containing a specified value.
Combinator Selectors
CSS combinators are used to define the relationship between selectors in CSS.
They help in selecting elements based on their relationship to other elements, which allows for more precise and efficient styling.
Descendant Combinator
myAscendantSelector myDescendantSelector { myProperty: myValue; }
A space is used between the parent and child selector.
A descendant combinator is used to target elements matched by the second selector if they are nested within an ancestor element that matches the first selector.
An ancestor can be a parent element or a parent's parent.
Child Combinator
myParentSelector > myChildSelector { myProperty: myValue; }
A child combinator is used to select elements that are direct children of a specified parent element.
This combinator targets only elements with a specific parent, making the CSS rules more precise and preventing unintended styling of deeper nested elements.
Next-sibling Combinator
mySelector1 + mySelector2 { myProperty: myValue; }
A next-sibling combinator selects an element that immediately follows a specified sibling element.
This combinator is useful when you want to apply styles to an element that directly follows another element, allowing for targeted styling based on the element's position relative to its siblings.
Subsequent-sibling Combinator
mySelector1 ~ mySelector2 { myProperty: myValue; }
A subsequent-sibling combinator selects all siblings of a specified element that come after it.
The combinator can target any siblings that follow the specified element, offering greater flexibility in styling.
Group Selectors
mySelector1, mySelector2 { myProperty: myValue; }
A group selector select a group of selector that has same CSS rules.
Instead of writing the same CSS rule for each selector one by one, a group selector can be used to avoid time consume.
CSS UNITS
Pixels are a fixed-size unit of measurement in CSS, providing precise control over dimensions.
LIST OF CSS PROPERTIES
colorSets the color of textfont-familySpecifies the font family for textfont-sizeSpecifies the font size of textfont-stretchSelects a normal, condensed, or expanded face from a font familyfont-styleSpecifies the font style for textfont-variantSpecifies whether or not a text should be displayed in a small-caps fontfont-weightSpecifies the weight of a fontline-heightSets the line heighttext-alignSpecifies the horizontal alignment of texttext-align-lastSpecifies the horizontal alignment of the last line texttext-decoration-colorSpecifies the color of the text-decorationtext-decoration-lineSpecifies the type of line in a text-decorationtext-decoration-styleSpecifies the style of the line in a text decorationtext-decoration-thicknessSpecifies the thickness of the decoration linetext-emphasis-colorSpecifies the color of emphasis markstext-emphasis-positionSpecifies the position of emphasis markstext-emphasis-styleSpecifies the style of emphasis markstext-indentSpecifies the indentation of the first line in a text-blocktext-justifySpecifies the justification method usedtext-orientationDefines the orientation of characters in a linetext-overflowSpecifies what should happen when text overflows the containing elementtext-shadowAdds shadow to texttext-transformControls the capitalization of texttext-underline-offsetSpecifies the offset distance of the underline text decorationtext-underline-positionSpecifies the position of the underline text decorationaccent-coloralign-contentalign-itemsalign-selfallanimationanimation-delayanimation-directionanimation-durationanimation-fill-modeanimation-iteration-countanimation-nameanimation-play-stateanimation-timing-functionaspect-ratiobackdrop-filterbackface-visibilitybackgroundbackground-attachmentbackground-blend-modebackground-clipbackground-colorbackground-imagebackground-originbackground-positionbackground-position-xbackground-position-ybackground-repeatbackground-sizeblock-sizeborderborder-blockborder-block-colorborder-block-endborder-block-end-colorborder-block-end-styleborder-block-end-widthborder-block-startborder-block-start-colorborder-block-start-styleborder-block-start-widthborder-block-styleborder-block-widthborder-bottomborder-bottom-colorborder-bottom-left-radiusborder-bottom-right-radiusborder-bottom-styleborder-bottom-widthborder-collapseborder-colorborder-end-end-radiusborder-end-start-radiusborder-imageborder-image-outsetborder-image-repeatborder-image-sliceborder-image-sourceborder-image-widthborder-inlineborder-inline-colorborder-inline-endborder-inline-end-colorborder-inline-end-styleborder-inline-end-widthborder-inline-startborder-inline-start-colorborder-inline-start-styleborder-inline-start-widthborder-inline-styleborder-inline-widthborder-leftborder-left-colorborder-left-styleborder-left-widthborder-radiusborder-rightborder-right-colorborder-right-styleborder-right-widthborder-spacingborder-start-end-radiusborder-start-start-radiusborder-styleborder-topborder-top-colorborder-top-left-radiusborder-top-right-radiusborder-top-styleborder-top-widthborder-widthbottombox-decoration-breakbox-reflectbox-shadowbox-sizingbreak-afterbreak-beforebreak-insidecaption-sidecaret-color@charsetclearclipclip-pathcolor-schemecolumn-countcolumn-fillcolumn-gapcolumn-rulecolumn-rule-colorcolumn-rule-stylecolumn-rule-widthcolumn-spancolumn-widthcolumns@containercontentcounter-incrementcounter-resetcounter-set@counter-stylecursordirectiondisplayempty-cellsfilterflexflex-basisflex-directionflex-flowflex-growflex-shrinkflex-wrapfloat@font-facefont-feature-settingsfont-kerning@font-palette-valuesfont-size-adjustfont-variant-capsgapgridgrid-areagrid-auto-columnsgrid-auto-flowgrid-auto-rowsgrid-columngrid-column-endgrid-column-startgrid-rowgrid-row-endgrid-row-startgrid-templategrid-template-areasgrid-template-columnsgrid-template-rowshanging-punctuationheighthyphenshyphenate-characterimage-rendering@importinitial-letterinline-sizeinsetinset-blockinset-block-endinset-block-startinset-inlineinset-inline-endinset-inline-startisolationjustify-contentjustify-itemsjustify-self@keyframes@layerleftletter-spacinglist-stylelist-style-imagelist-style-positionlist-style-typemarginmargin-blockmargin-block-endmargin-block-startmargin-bottommargin-inlinemargin-inline-endmargin-inline-startmargin-leftmargin-rightmargin-topmarkermarker-endmarker-midmarker-startmaskmask-clipmask-compositemask-imagemask-modemask-originmask-positionmask-repeatmask-sizemask-typemax-block-sizemax-heightmax-inline-sizemax-width@mediamin-block-sizemin-inline-sizemin-heightmin-widthmix-blend-mode@namespaceobject-fitobject-positionoffsetoffset-anchoroffset-distanceoffset-pathoffset-positionoffset-rotateopacityorderorphansoutlineoutline-coloroutline-offsetoutline-styleoutline-widthoverflowoverflow-anchoroverflow-wrapoverflow-xoverflow-yoverscroll-behavioroverscroll-behavior-blockoverscroll-behavior-inlineoverscroll-behavior-xoverscroll-behavior-ypaddingpadding-blockpadding-block-endpadding-block-startpadding-bottompadding-inlinepadding-inline-endpadding-inline-startpadding-leftpadding-rightpadding-top@pagepage-break-afterpage-break-beforepage-break-insidepaint-orderperspectiveperspective-originplace-contentplace-itemsplace-selfpointer-eventsposition@propertyquotesresizerightrotaterow-gapscale@scopescroll-behaviorscroll-marginscroll-margin-blockscroll-margin-block-endscroll-margin-block-startscroll-margin-bottomscroll-margin-inlinescroll-margin-inline-endscroll-margin-inline-startscroll-margin-leftscroll-margin-rightscroll-margin-topscroll-paddingscroll-padding-blockscroll-padding-block-endscroll-padding-block-startscroll-padding-bottomscroll-padding-inlinescroll-padding-inline-endscroll-padding-inline-startscroll-padding-leftscroll-padding-rightscroll-padding-topscroll-snap-alignscroll-snap-stopscroll-snap-typescrollbar-colorshape-outside@starting-style@supportstab-sizetable-layouttoptransformtransform-origintransform-styletransitiontransition-delaytransition-durationtransition-propertytransition-timing-functiontranslateunicode-bidiuser-selectvertical-alignvisibilitywhite-spacewidowswidthword-breakword-spacingword-wrapwriting-modez-indexzoom
COLOR PROPERTY
The color property specifies the color of text.
FONT-FAMILY PROPERTY
The font-family property specifies the font for an element.
The font-family property can hold several font names as a "fallback" system.
If the browser does not support the first font, it tries the next font.
There are two types of font family names:
Family-Name (The name of a font-family): "times", "courier", "arial", etc.
Generic-Family (The name of a generic-family): "serif", "sans-serif", "cursive", "fantasy", "monospace"
FONT-SIZE PROPERTY
The font-size property sets the size of a font.
FONT-STRETCH PROPERTY
The font-stretch property allows the text narrower (condensed) or wider (expanded).
Some fonts provide additional faces; condensed faces and expanded faces.
This property has no effect if the selected font does not offer condensed or expanded faces.
FONT-STYLE PROPERTY
The font-style property specifies the font style for a text.
FONT-VARIANT PROPERTY
The font-variant property specifies whether or not a text should be displayed in a small-caps font.
FONT-WEIGHT PROPERTY
The font-weight property sets how thick or thin characters in text should be displayed.
LINE-HEIGHT PROPERTY
The line-height property specifies the height of a line.
TEXT-ALIGN PROPERTY
The text-align property specifies the horizontal alignment of text in an element.
TEXT-ALIGN-LAST PROPERTY
The text-align-last property specifies how to align the last line of a text.
The text-align-last property only works if text-align: justify; is set.
Notice that the text-align-last property sets the alignment for all last lines within the selected element.
Example; If there is a div element with 3 p in it, text-align-last will apply to the last line of EACH of the paragraphs.
TEXT-DECORATION COLOR PROPERTY
The text-decoration-color property specifies the color of the text-decoration.
TEXT-DECORATION-LINE PROPERTY
The text-decoration-line property sets the kind of text decoration to use.
TEXT-DECORATION-STYLE PROPERTY
The text-decoration-style property sets the style of the text decoration.
TEXT-DECORATION-THICKNESS PROPERTY
The text-decoration-thickness property specifies the thickness of the decoration line.
TEXT-EMPHASIS-COLOR PROPERTY
The text-emphasis-color property sets the color of emphasis marks.
TEXT-EMPHASIS-POSITION PROPERTY
The text-emphasis-position property specifies the position of the emphasis marks.
The writing-mode property is used to specify horizontal or vertical writing mode.
TEXT-EMPHASIS-STYLE PROPERTY
The text-emphasis-style property sets the style of emphasis marks.
TEXT-INDENT PROPERTY
The text-indent property specifies the indentation of the first line in a text-block.
Negative values are allowed where the first line will be indented to the left.
TEXT-JUSTIFY PROPERTY
The text-justify property specifies the justification method of text
TEXT-ORIENTATION PROPERTY
The text-orientation property specifies the orientation of characters.
Works only when writing-mode: vertical; is set.
TEXT-OVERFLOW PROPERTY
The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user.
TEXT-SHADOW PROPERTY
The text-shadow property adds shadow to text.
TEXT-TRANSFORM PROPERTY
The text-transform property controls the capitalization of text.
TEXT-UNDERLINE-OFFSET PROPERTY
The text-underline-offset property specifies the offset distance of underline text decorations.
TEXT-UNDERLINE-POSITION PROPERTY
The text-underline-position property specifies the position of underline text decorations.
EXAMPLE PROPERTY
The EXAMPLE EXAMPLE.