This document provides an overview of CSS essential concepts including values and units, the box model, overflow content, styling images and lists. It covers topics such as data types for CSS values, length units, colors, block and inline boxes, the CSS box model, margins, paddings and borders, the overflow property and rounded borders.
This document provides an overview of CSS essential concepts including values and units, the box model, overflow content, styling images and lists. It covers topics such as data types for CSS values, length units, colors, block and inline boxes, the CSS box model, margins, paddings and borders, the overflow property and rounded borders.
CSS Value ➢ CSS value: Every CSS declaration includes a property / value pair. Depending on the property, the value can include a single integer or keyword, to a series of keywords and values with or without units
Distance unit ➢ Distance unit (length unit): There are 2 types of distance unit in CSS: Relative and Absolute ❖ Absolute length units are fixed to a physical length
Percentage ➢ Percentage is a type that represents a fraction of some other value. ➢ It is always relative to another quantity. ➢ Each property that allows percentages also defines the quantity to which the percentage refers. ➢ This quantity can be a value of another property of the same element, the value of a property of an ancestor element, a measurement of a containing block, or something else.
GRB Colors ➢ An RGB color value is specified with the rgb() function, which has the following syntax: rgb(red, green, blue) ➢ Each parameter (red, green, and blue) defines the intensity of the color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%).
Block and Inline boxes ➢ Block box: ▪ The box will break onto a new line. ▪ The width and height properties are respected. ▪ Padding, margin and border will cause other elements to be pushed away from the box
Block and Inline boxes ➢ Inline box: ▪ The box will not break onto a new line. ▪ The width and height properties will not apply. ▪ Vertical padding, margins, and borders will apply but will not cause other inline boxes to move away from the box. ▪ Horizontal padding, margins, and borders will apply and will cause other inline boxes to move away from the box
The CSS Box Model ➢ Making up a block box in CSS we have: ▪ Content box: The area where your content is displayed, which can be sized using properties like width and height. ▪ Padding box: The padding sits around the content as white space; its size can be controlled using padding and related properties. ▪ Border box: The border box wraps the content and any padding. Its size and style can be controlled using border and related properties. ▪ Margin box: The margin is the outermost layer, wrapping the content, padding and border as whitespace between this box and other elements. Its size can be controlled using margin and related properties.
Use browser DevTools to view the box model ➢ If you inspect an element in browser DevTools, you can see the size of the element plus its margin, padding, and border. Inspecting an element in this way is a great way to find out if your box is really the size you think it is
Margins, paddings and borders ➢ Margin: Is an invisible space around your box. It pushes other elements away from the box. Margins can have positive or negative values. Setting a negative margin on one side of your box can cause it to overlap other things on the page ➢ We can control all margins of an element at once using the margin property, or each side individually using the equivalent longhand properties: ▪ margin-top ▪ margin-right ▪ margin-bottom ▪ margin-left
Margins, paddings and borders ➢ Padding: Sits between the border and the content area. Unlike margins you cannot have negative amounts of padding, so the value must be 0 or a positive value, it is typically used to push the content away from the border. ➢ We can control all margins of an element at once using the margin property, or each side individually using the equivalent longhand properties: ▪ padding-top ▪ padding-right ▪ padding-bottom ▪ padding-left
CSS Shorthand Clockwise ▪ To shorten the code, it is possible to specify all the margin/ or padding/ or border properties in one property ✓ 1 value: all sides ✓ 2 values: top-bottom, right-left ✓ 4 values: top-right-bottom-left ✓ 3 values: top, right-left, bottom
What is overflow? ➢ Overflow: Is a css property sets what to do when an element's content is too big to fit in its block formatting context. ➢ This demo below is default value of overflow property:
Overflow property ➢ Value: ▪ hidden: Content is clipped if necessary to fit the padding box. No scrollbars are provided, and no support for allowing the user to scroll
Overflow property ➢ Value: ▪ scroll: Content is clipped if necessary to fit the padding box. Browsers always display scrollbars whether or not any content is actually clipped, preventing scrollbars from appearing or disappearing as content changes
Overflow property ➢ Value: ▪ auto: Depends on the user agent. If content fits inside the padding box, it looks the same as visible, but still establishes a new block formatting context. Desktop browsers provide scrollbars if content overflows.
Styling images ➢ Responsive images If you want an image to scale down if it has to, but never scale up to be larger than its original size, use max-width: 100%
If you want to restrict a responsive image to a maximum size, use the max-width property, with a pixel value of your choice
Styling images ➢ Center an image: To center an image, set left and right margin to auto and make it into a block element ➢ Transparent image: The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent