Quiz Weeks 5/6 Flashcards
Gradient Definition/Basics
Is a transition from one color to another, sometimes through multiple colors.
A gradient is considered an image created on the fly and can be applied to any element an image can be applied to.
A gradient image has no intrinsic size or proportions; the size matches the element it gets applied to.
Advantages of Gradients
They do not require an extra call to the server and require fewer bytes to download than images.
Disadvantages of Gradients
On the other hand, all that rendering on the fly requires time and processing power that can hurt performance.
Two types of gradients
- Linear gradients change colors along a line, from one edge of the element to the other.
- Radial gradients start at a point and spread outward in a circular or elliptical shape.
Linear-gradient() notation
Provides the angle of the gradient line and one or more points along that line where the pure color is positioned.
Can use degrees or keywords to describe angle of linear
With degrees, 0deg points upward, and positive angles go around clockwise so that 90deg points to the right.
The keywords describe direction in increments of 90° (to top, to right, to bottom, to left).
Color length
You can use percentages or any length measurement to set color lengths in a gradient.
If no positions are specified, the colors are spaced evenly across the length of the gradient line.
Radial gradients
Radiate out from a point in a circle along a gradient ray (like a gradient line, but it always points outward from the center).
At minimum, a radial gradient requires two color stops.
Radial-gradient() notation
Allows you to specify the shape, size, and center position of the gradient.
In most cases, the shape of the radial gradient will result from the shape of the element or an explicit size you apply to it, but you can also specify the shape by using the circle or ellipse keywords.
The size of the radial gradient can be specified in length units or percentages, which apply to the gradient ray, or with keywords. If you supply just one length, it is used for both width and height, resulting in a circle. When you provide two lengths, the first one is the horizontal measurement and the second is vertical.
Radial-gradient position notation
Closest-side, closest-corner, farthest-side, and farthest-corner—that set the length of the gradient ray relative to points on the containing element.
By default, the center of the gradient is positioned at center center, but you can change that by using the positioning syntax we covered for the background-position property.
Radial-gradient repeating notation
Use the repeating-linear-gradient() or repeating-radial-gradient() notation.
The box model definition/basics
According to the box model, every element in a document generates a box to which properties such as width, height, padding, borders, and margins can be applied.
Every element in a document, both block-level and inline, generates a rectangular element box.
Parts of an element box: Content area
At the core of the element box is the content itself. The edges of the content area are referred to as the inner edges of the element box.
In real pages, the edge of the content area is invisible.
Parts of an element box: Padding
The padding is the area between the content area and an optional border. Padding is optional.
Parts of an element box: Border
The border is a line (or stylized line) that surrounds the element and its padding. Borders are also optional.
Parts of an element box: Margin
The margin is an optional amount of space added on the outside of the border.
In reality, margins are always transparent, allowing the background of the parent element to show through.
Parts of an element box: Outer edge
The outside edges of the margin area make up the outer edges of the element box. This is the total area the element takes up on the page, and it includes the width of the content area plus the total amount of padding, border, and margins applied to the element.
In real web pages, the edge of the margin is invisible.
Specifying box dimensions: width/height (properties)
Values: length | percentage | auto
Default: auto
Applies to: block-level elements and replaced inline elements (such as images)
Inherits: no
Specifying box dimensions: box-sizing (properties)
Values: content-box | border-box
Default: content-box
Applies to: all elements
Inherits: no
Auto value in width/height of block element/box
By default, the width and height of a block element are calculated automatically by the browser. However, you can use the width and height properties to make the content area of an element a specific width or height.
There are two ways to specify the size of an element
- The default method: Applies the width and height values to the content box. That means that the resulting size of the element will be the dimensions you specify plus the amount of padding and borders that have been added to the element.
- Using box-sizing property: applies the width and height values to the border box, which includes the content, padding, and border. With this method, the resulting visible element box, including padding and borders, will be exactly the dimensions you specify.
Width and height for block-level vs. inline
Regardless of the method you choose, you can specify the width and height only for block-level elements and non-text inline elements such as images.
The width and height properties do not apply to inline text (non-replaced) elements and are ignored by the browser.
Box-sizing: content-box
By default, the width and height properties are applied to the content box. But, you can explicitly specify this behavior by setting box-sizing: content-box.
Box-sizing: border-box
The other way to specify the size of an element is to apply width and height dimensions to the entire visible box, including the padding and border. Not the default browser behavior, and needs to be set to box-sizing: border-box in the style sheet. Many developers simply set everything in the document to use the border-box model by setting it on the root (html) element, then setting all other elements to inherit, like this:
html {box-sizing: border-box;}
*, *:before, *:after {box-sizing: inherit;}
Border-box warning
Avoid using max- and min- widths and heights with the border-box model. They are known to cause browser problems.
Height property in relation to width
Works just the same as width. In general practice, it is less common to specify the height of elements. Not including allows the height to be calculated automatically, allowing the element box to change based on the font size, user settings, or other factors.
Overflow property
When an element is sized too small for its contents, you can specify what to do with the content that doesn’t fit by using the overflow property.
Overflow property (properties)
Values: visible | hidden | scroll | auto
Default: visible
Applies to: block-level elements and replaced inline elements (such as images)
Inherits: no
Values of overflow property: visible
The default value is visible, which allows the content to hang out over the element box so that it all can be seen.
Values of overflow property: hidden
When overflow is set to hidden, the content that does not fit gets clipped off and does not appear beyond the edges of the element’s content area.
Values of overflow property: scroll
When scroll is specified, scrollbars are added to the element box to let users scroll through the content. Be aware that they may become visible only when you click the element to scroll it. Is a simpler alternative to overflow:scroll for mobile.
Values of overflow property: auto
The auto value allows the browser to decide how to handle overflow. In most cases, scrollbars are added only when the content doesn’t fit and they are needed.
Box-shadow property
Applies a drop shadow around the entire visible element box (excluding the margin).
Box-shadow property (properties)
Values: ‘horizontal offset’ ‘vertical offset’ ‘blur distance’ ‘spread distance’ color inset | none
Default: none
Applies to: all elements
Inherits: no