Defines how long the animation has to wait before starting. The animation will only be delayed on its first iteration.
default
animation-delay: 0s;
The animation will wait zero seconds, and thus start right away.
animation-delay: 1.2s;
You can use decimal values in seconds with the keyword s
.
animation-delay: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
animation-delay: -500ms;
You can use negative values: the animation will start as if it had already been playing for 500ms
.
Defines in which direction the animation is played.
default
animation-direction: normal;
The animation is played forwards. When it reaches the end, it starts over at the first keyframe.
animation-direction: reverse;
The animation is played backwards: begins at the last keyframe, finishes at the first keyframe.
animation-direction: alternate;
The animation is played forwards first, then backwards:
animation-direction: alternate-reverse;
The animation is played backwards first, then forwards:
Defines how long the animation lasts.
default
animation-duration: 0s;
The default value is zero seconds: the animation will simply not play.
animation-duration: 1.2s;
You can use decimal values in seconds with the keyword s
.
animation-duration: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
Defines what happens before an animation starts and after it ends. The fill mode allows to tell the browser if the animation’s styles should also be applied outside of the animation.
default
animation-fill-mode: none;
The animation styles do not affect the default style: the element is set to its default state before the animation starts, and returns to that default state after the animation ends.
animation-fill-mode: forwards;
The last styles applied at the end of the animation are retained afterwards.
animation-fill-mode: backwards;
The animation's styles will already be applied before the animation actually starts.
animation-fill-mode: both;
The styles are applied before and after the animation plays.
Defines how many times the animation is played.
default
animation-iteration-count: 1;
The animation will only play once.
animation-iteration-count: 2;
You can use integer values to define a specific amount of times the animation will play.
animation-iteration-count: infinite;
By using the keyword infinite
, the animation will play indefinitely.
Defines which animation keyframes to use.
default
animation-name: none;
If no animation name is specified, no animation is played.
animation-name: fadeIn;
If a name is specified, the keyframes matching that name will be used.
For example, the fadeIn
animation looks like this:
@keyframes fadeIn { +#animation-delay
Defines how long the animation has to wait before starting. The animation will only be delayed on its first iteration.
默认属性
animation-delay: 0s;
The animation will wait zero seconds, and thus start right away.
animation-delay: 1.2s;
You can use decimal values in seconds with the keyword
s
.
animation-delay: 2400ms;
You can use milliseconds instead of seconds, with the keyword
ms
.
animation-delay: -500ms;
You can use negative values: the animation will start as if it had already been playing for
500ms
.#animation-direction
Defines in which direction the animation is played.
默认属性
animation-direction: normal;
The animation is played forwards. When it reaches the end, it starts over at the first keyframe.
animation-direction: reverse;
The animation is played backwards: begins at the last keyframe, finishes at the first keyframe.
animation-direction: alternate;
The animation is played forwards first, then backwards:
- starts at the first keyframe
- stops at the last keyframe
- starts again, but at the last keyframe
- stops at the first keyframe
animation-direction: alternate-reverse;
The animation is played backwards first, then forwards:
- starts at the last keyframe
- stops at the first keyframe
- starts again, but at the first keyframe
- stops at the last keyframe
#animation-duration
Defines how long the animation lasts.
默认属性
animation-duration: 0s;
The default value is zero seconds: the animation will simply not play.
animation-duration: 1.2s;
You can use decimal values in seconds with the keyword
s
.
animation-duration: 2400ms;
You can use milliseconds instead of seconds, with the keyword
ms
.#animation-fill-mode
Defines what happens before an animation starts and after it ends. The fill mode allows to tell the browser if the animation’s styles should also be applied outside of the animation.
默认属性
animation-fill-mode: none;
The animation styles do not affect the default style: the element is set to its default state before the animation starts, and returns to that default state after the animation ends.
animation-fill-mode: forwards;
The last styles applied at the end of the animation are retained afterwards.
animation-fill-mode: backwards;
The animation's styles will already be applied before the animation actually starts.
animation-fill-mode: both;
The styles are applied before and after the animation plays.
#animation-iteration-count
Defines how many times the animation is played.
默认属性
animation-iteration-count: 1;
The animation will only play once.
animation-iteration-count: 2;
You can use integer values to define a specific amount of times the animation will play.
animation-iteration-count: infinite;
By using the keyword
infinite
, the animation will play indefinitely.#animation-name
Defines which animation keyframes to use.
默认属性
animation-name: none;
If no animation name is specified, no animation is played.
animation-name: fadeIn;
If a name is specified, the keyframes matching that name will be used.
For example, the
fadeIn
animation looks like this:@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } -}
animation-name: moveRight;
Another example: the
moveRight
animation:@keyframes moveRight { +}
animation-name: moveRight;
Another example: the
moveRight
animation:@keyframes moveRight { from { transform: translateX(0); } to { transform: translateX(100px); } -}#animation-play-state
Defines if an animation is playing or not.
default
animation-play-state: running;
If the
animation-duration
andanimation-name
are defined, the animation will start playing automatically.
animation-play-state: paused;
The animation is set paused at the first keyframe.
This is different than having either no
animation-duration
oranimation-name
at all. If the animation is paused, the style applied is that of the first keyframe, and not the default style.In this example, the square is visible by default, but the on the first keyframe of
fadeAndMove
, theopacity
is set to0
. When paused, the animation will be "stuck" on this first keyframe, and will thus be invisible.@keyframes fadeAndMove { +}#animation-play-state
Defines if an animation is playing or not.
默认属性
animation-play-state: running;
If the
animation-duration
andanimation-name
are defined, the animation will start playing automatically.
animation-play-state: paused;
The animation is set paused at the first keyframe.
This is different than having either no
animation-duration
oranimation-name
at all. If the animation is paused, the style applied is that of the first keyframe, and not the default style.In this example, the square is visible by default, but the on the first keyframe of
fadeAndMove
, theopacity
is set to0
. When paused, the animation will be "stuck" on this first keyframe, and will thus be invisible.@keyframes fadeAndMove { from { opacity: 0; transform: translateX(0); @@ -21,4 +21,4 @@ opacity: 0; transform: translateX(100px); } -}#animation-timing-function
Defines how the values between the start and the end of the animation are calculated.
default
animation-timing-function: ease;
The animation starts slowly, accelerates in the middle, and slows down at the end.
animation-timing-function: ease-in;
The animation starts slowly, and accelerates gradually until the end.
animation-timing-function: ease-out;
The animation starts quickly, and decelerates gradually until the end.
animation-timing-function: ease-in-out;
Like
ease
, but more pronounced.The animation starts quickly, and decelerates gradually until the end.
animation-timing-function: linear;
The animation has a *constant speed.
animation-timing-function: step-start;
The animation jumps instantly to the final state.
animation-timing-function: step-end;
The animation stays at the initial state until the end, when it instantly jumps to the final state.
animation-timing-function: steps(4, end);
By using
steps()
with an integer, you can define a specific number of steps before reaching the end. The state of the element will not vary gradually, but rather jump from state to state in separate instants.\ No newline at end of file +} #animation
Shorthand property for
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
andanimation-play-state
.Only
animation-duration
andanimation-name
are required.
Defines how the values between the start and the end of the animation are calculated.
默认属性
animation-timing-function: ease;
The animation starts slowly, accelerates in the middle, and slows down at the end.
animation-timing-function: ease-in;
The animation starts slowly, and accelerates gradually until the end.
animation-timing-function: ease-out;
The animation starts quickly, and decelerates gradually until the end.
animation-timing-function: ease-in-out;
Like ease
, but more pronounced.
The animation starts quickly, and decelerates gradually until the end.
animation-timing-function: linear;
The animation has a *constant speed.
animation-timing-function: step-start;
The animation jumps instantly to the final state.
animation-timing-function: step-end;
The animation stays at the initial state until the end, when it instantly jumps to the final state.
animation-timing-function: steps(4, end);
By using steps()
with an integer, you can define a specific number of steps before reaching the end. The state of the element will not vary gradually, but rather jump from state to state in separate instants.
Shorthand property for animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
and animation-play-state
.
Only animation-duration
and animation-name
are required.
Defines how the background image will behave when scrolling the page.
default
background-attachment: scroll;
The background image will scroll with the page. It will also position and resize itself according to the element it's applied to.
background-attachment: fixed;
The background image will not scroll with the page, and remain positioned according to the viewport. It will also position and resize itself according to the viewport. As a result, the background image will probably only be partially visible.
Defines how far the background should extend within the element.
default
background-clip: border-box;
The background extends completely throughout the element, even under the border.
background-clip: padding-box;
The background only extends to the edge of the border: it includes the padding but not the border.
background-clip: content-box;
The background only extends to the edge of the content: it doesn't include the padding, nor the border.
Defines the color of the element's background.
default
background-color: transparent;
By default, the background color is transparent, basically meaning that there is no background color.
background-color: red;
You can use one of the 140+ color names.
background-color: #05ffb0;
You can use hexadecimal color codes.
background-color: rgb(50, 115, 220);
You can use rgb() color codes:
red
green
blue
Each of them can have a value between 0 and 255.
background-color: rgba(50, 115, 220, 0.3);
You can use rgba() color codes:
rgb
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
background-color: hsl(14, 100%, 53%);
You can use hsl() color codes:
hue
and can go from 0 to 359saturation
and go from 0% to 100%luminosity
and go from 0% to 100%background-color: hsla(14, 100%, 53%, 0.6);
You can use hsl()a color codes:
hsl
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
Defines an image as the background of the element.
default
background-image: none;
Removes any background image.
background-image: url(/images/jt.png);
Uses the image defined in the url path. This path can either be relative (to the css file) or absolute (like http://cssreference.io/images/jt.png
).
background-image: linear-gradient(red, blue);
You can define a linear gradient as the background image.
You need to define at least two colors. The first one will start at the top, the second one at the bottom.
The default angle is to bottom
(or 180deg
), which means the gradient is vertical, starting at the top, ending at the bottom of the element.
background-image: linear-gradient(45deg, red, blue);
You can specify an angle, either in degrees, or with keywords.
When using degress, you specify the direction of the gradient, or when it ends. So 0deg
means the the top of the element, like 12:00 on a clock.
In this example, 45deg
means 2:30, or the top right corner.
background-image: radial-gradient(green, purple);
You can define a radial gradient as the background image.
You need to define at least two colors. The first one will be at the center, the second one at the edges.
background-image: radial-gradient(circle, green, purple);
You can specify the shape of the radial gradient: circle or ellipse (default).
background-image: radial-gradient(circle, green 0%, purple 20%, orange 100%);
You can specify color stops using percentage values.
background-image: radial-gradient(circle closest-side, green 0%, purple 20%, orange 100%);
You can specify where the gradient should end:
closest-side
closest-corner
farthest-side
farthest-corner
background-image: radial-gradient(circle closest-side at 45px 45px, green 0%, purple 20%, orange 100%);
Like with the background-position
, you can specify the position of the gradient.
Defines the origin of the background image.
default
background-origin: padding-box;
The background image starts at the edge of the border: within padding but not the border.
background-origin: border-box;
The background image starts under the border.
background-origin: content-box;
The background image only starts at the edge of the content: it doesn't include the padding, nor the border.
Defines the position of the background image.
default
background-position: 0% 0%;
The background image will be positioned at 0% on the horizontal axis and 0% on the vertical axis, which means the top left corner of the element.
background-position: bottom right;
You can use a combination of position keywords: center
, top
, bottom
, left
and right
.
background-position: center center;
The background image will be positioned in the center of the element.
Defines how the background image repeats itself across the element's background, starting from the background position.
default
background-repeat: repeat;
The background image will repeat itself both horizontally and vertically.
background-repeat: repeat-x;
The background image will only repeat itself horizontally.
background-repeat: repeat-y;
The background image will only repeat itself vertically.
background-repeat: no-repeat;
The background image will only appear once.
Defines the size of the background image.
default
background-size: auto auto;
The background image will retain its original size.
For example, this background image is 960px by 640px large. Its aspect ratio is 3 by 2. It's bigger than its container (which is 150px high) and will thus be clipped.
background-size: 120px 80px;
You can specify a size in pixels:
background-size: 100% 50%;
You can use percentage values as well. Beware that this can alter the aspect ratio of the background image, and lead to unexpected results.
background-size: contain;
The keyword contain
will resize the background image to make sure it remains fully visible.
background-size: cover;
The keyword cover
will resize the background image to make sure the element is fully covered.
Shorthand property for background-image
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
and background-color
.
Defines how the background image will behave when scrolling the page.
默认属性
background-attachment: scroll;
The background image will scroll with the page. It will also position and resize itself according to the element it's applied to.
background-attachment: fixed;
The background image will not scroll with the page, and remain positioned according to the viewport. It will also position and resize itself according to the viewport. As a result, the background image will probably only be partially visible.
Defines how far the background should extend within the element.
默认属性
background-clip: border-box;
The background extends completely throughout the element, even under the border.
background-clip: padding-box;
The background only extends to the edge of the border: it includes the padding but not the border.
background-clip: content-box;
The background only extends to the edge of the content: it doesn't include the padding, nor the border.
Defines the color of the element's background.
默认属性
background-color: transparent;
By default, the background color is transparent, basically meaning that there is no background color.
background-color: red;
You can use one of the 140+ color names.
background-color: #05ffb0;
You can use hexadecimal color codes.
background-color: rgb(50, 115, 220);
You can use rgb() color codes:
red
green
blue
Each of them can have a value between 0 and 255.
background-color: rgba(50, 115, 220, 0.3);
You can use rgba() color codes:
rgb
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
background-color: hsl(14, 100%, 53%);
You can use hsl() color codes:
hue
and can go from 0 to 359saturation
and go from 0% to 100%luminosity
and go from 0% to 100%background-color: hsla(14, 100%, 53%, 0.6);
You can use hsl()a color codes:
hsl
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
Defines an image as the background of the element.
默认属性
background-image: none;
Removes any background image.
background-image: url(/images/jt.png);
Uses the image defined in the url path. This path can either be relative (to the css file) or absolute (like http://cssreference.parryqiu.com/images/jt.png
).
background-image: linear-gradient(red, blue);
You can define a linear gradient as the background image.
You need to define at least two colors. The first one will start at the top, the second one at the bottom.
The default angle is to bottom
(or 180deg
), which means the gradient is vertical, starting at the top, ending at the bottom of the element.
background-image: linear-gradient(45deg, red, blue);
You can specify an angle, either in degrees, or with keywords.
When using degress, you specify the direction of the gradient, or when it ends. So 0deg
means the the top of the element, like 12:00 on a clock.
In this example, 45deg
means 2:30, or the top right corner.
background-image: radial-gradient(green, purple);
You can define a radial gradient as the background image.
You need to define at least two colors. The first one will be at the center, the second one at the edges.
background-image: radial-gradient(circle, green, purple);
You can specify the shape of the radial gradient: circle or ellipse (default).
background-image: radial-gradient(circle, green 0%, purple 20%, orange 100%);
You can specify color stops using percentage values.
background-image: radial-gradient(circle closest-side, green 0%, purple 20%, orange 100%);
You can specify where the gradient should end:
closest-side
closest-corner
farthest-side
farthest-corner
background-image: radial-gradient(circle closest-side at 45px 45px, green 0%, purple 20%, orange 100%);
Like with the background-position
, you can specify the position of the gradient.
Defines the origin of the background image.
默认属性
background-origin: padding-box;
The background image starts at the edge of the border: within padding but not the border.
background-origin: border-box;
The background image starts under the border.
background-origin: content-box;
The background image only starts at the edge of the content: it doesn't include the padding, nor the border.
Defines the position of the background image.
默认属性
background-position: 0% 0%;
The background image will be positioned at 0% on the horizontal axis and 0% on the vertical axis, which means the top left corner of the element.
background-position: bottom right;
You can use a combination of position keywords: center
, top
, bottom
, left
and right
.
background-position: center center;
The background image will be positioned in the center of the element.
Defines how the background image repeats itself across the element's background, starting from the background position.
默认属性
background-repeat: repeat;
The background image will repeat itself both horizontally and vertically.
background-repeat: repeat-x;
The background image will only repeat itself horizontally.
background-repeat: repeat-y;
The background image will only repeat itself vertically.
background-repeat: no-repeat;
The background image will only appear once.
Defines the size of the background image.
默认属性
background-size: auto auto;
The background image will retain its original size.
For example, this background image is 960px by 640px large. Its aspect ratio is 3 by 2. It's bigger than its container (which is 150px high) and will thus be clipped.
background-size: 120px 80px;
You can specify a size in pixels:
background-size: 100% 50%;
You can use percentage values as well. Beware that this can alter the aspect ratio of the background image, and lead to unexpected results.
background-size: contain;
The keyword contain
will resize the background image to make sure it remains fully visible.
background-size: cover;
The keyword cover
will resize the background image to make sure the element is fully covered.
Shorthand property for background-image
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
and background-color
.
Like border-width
, but for the bottom border only.
default
border-bottom-width: 0;
Removes the bottom border.
border-bottom-width: 4px;
You can use pixel values.
Like border-width
, but for the left border only.
default
border-left-width: 0;
Removes the left border.
border-left-width: 4px;
You can use pixel values.
Like border-width
, but for the right border only.
default
border-right-width: 0;
Removes the right border.
border-right-width: 4px;
You can use pixel values.
Like border-width
, but for the top border only.
default
border-top-width: 0;
Removes the top border.
border-top-width: 4px;
You can use pixel values.
Defines the width of the element's borders.
border-width: 1px;
Defines the width of all borders to 1px.
border-width: 2px 0;
Defines the top and bottom borders to 2px, the left and right to 0.
Defines how the width and height of the element are calculated: whether they include the padding and borders or not.
default
box-sizing: content-box;
The width and height of the element only apply to the content of the element.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
The full width is 24px + 60px + 200px = 284px.
The content has the defined width. The box accomodates for those dimensions.
box-sizing: border-box;
The width and height of the element apply to all parts of the element: the content, the padding and the borders.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
The full width is 200px, no matter what.
The box has the defined width. The content accomodates for those dimensions, and ends up being 200px - 60px - 24px = 116px.
Defines the height of the element.
default
height: auto;
The element will automatically adjust its height to allow its content to be displayed correctly.
height: 100px;
You can use numeric values like pixels, (r)em, percentages...
If the content does not fit within the specified height, it will overflow. How the container will handle this overflowing content is defined by the overflow
property.
Defines the height of a single line of text.
default
line-height: normal;
Reverts to the default value of the browser.
recommended
line-height: 1.6;
You can use unitless values: the line height will be relative to the font size.
line-height: 30px;
You can use pixel values.
line-height: 0.8em;
You can use em values: like with unitless values, the line height will be relative to the font size.
Defines the space outside the element, on the bottom side.
default
margin-bottom: 0;
Removes any margin at the bottom.
margin-bottom: 30px;
You can use pixel values.
margin-bottom: 2em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-bottom: 10%;
You can use percentage values.
The percentage is based on the width of the container.
Defines the space outside the element, on the left side.
default
margin-left: 0;
Removes any margin on the left.
margin-left: 50px;
You can use pixel values.
margin-left: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-left: 30%;
You can use percentage values.
The percentage is based on the width of the container.
margin-left: auto;
The auto keyword will give the left side a share of the remaining space.
When combined with margin-right: auto
, it will center the element, if a fixed width is defined.
Defines the space outside the element, on the right side.
default
margin-right: 0;
Removes any margin on the right.
margin-right: 50px;
You can use pixel values.
margin-right: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-right: 30%;
You can use percentage values.
The percentage is based on the width of the container.
margin-right: auto;
The auto keyword will give the right side a share of the remaining space.
When combined with margin-left: auto
, it will center the element, if a fixed width is defined.
Defines the space outside the element, on the top side.
default
margin-top: 0;
Removes any margin at the top.
margin-top: 30px;
You can use pixel values.
margin-top: 2em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-top: 10%;
You can use percentage values.
The percentage is based on the width of the container.
Shorthand property for margin-top
margin-right
margin-bottom
and margin-left
.
default
margin: 0;
Removes all margins.
margin: 30px;
When using 1 value, the margin is set for all 4 sides.
margin: 30px 60px;
When using 2 values:
To remember the order think about the values you haven't defined.
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
margin: 30px 60px 45px;
When using 3 values:
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
margin: 30px 60px 45px 85px;
When using 4 values:
To remember the order, start at the top and go clockwise.
Defines the maximum height the element can be.
default
max-height: none;
The element has no limit in terms of height.
max-height: 2000px;
You can use numeric values like pixels, (r)em, percentages...
If the maximum height is larger than the element's actual height, the max height has no effect.
max-height: 100px;
If the content does not fit within the maximum height, it will overflow. How the container will handle this overflowing content is defined by the overflow
property.
Defines the maximum width the element can be.
default
max-width: none;
The element has no limit in terms of width.
max-width: 2000px;
You can use numeric values like pixels, (r)em, percentages...
If the maximum width is larger than the element's actual width, the max width has no effect.
max-width: 150px;
If the content does not fit within the maximum width, it will automatically change the height of the element to accomodate for the wrapping of the content.
Defines the minimum height of the element.
default
min-height: 0;
The element has no minimum height.
min-height: 200px;
You can use numeric values like pixels, (r)em, percentages...
If the minimum height is larger than the element's actual height, the min height will be applied.
min-height: 5px;
If the minimum height is smaller than the element's actual height, the min height has no effect.
Defines the minimum width of the element.
default
min-width: 0;
The element has no minimum width.
min-width: 300px;
You can use numeric values like pixels, (r)em, percentages...
If the minimum width is larger than the element's actual width, the min width will be applied.
min-width: 5px;
If the minimum width is smaller than the element's actual width, the min width has no effect.
Defines the space inside the element, on the bottom side.
default
padding-bottom: 0;
Removes any padding on the bottom.
padding-bottom: 50px;
You can use pixel values.
padding-bottom: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-bottom: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the left side.
default
padding-left: 0;
Removes any padding on the left.
padding-left: 50px;
You can use pixel values.
padding-left: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-left: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the right side.
default
padding-right: 0;
Removes any padding on the right.
padding-right: 50px;
You can use pixel values.
padding-right: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-right: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the top side.
default
padding-top: 0;
Removes any padding on the top.
padding-top: 50px;
You can use pixel values.
padding-top: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-top: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Shorthand property for padding-top
padding-right
padding-bottom
and padding-left
.
default
padding: 0;
Removes all paddings.
padding: 30px;
When using 1 value, the padding is set for all 4 sides.
padding: 30px 60px;
When using 2 values:
To remember the order think about the values you haven't defined.
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
padding: 30px 60px 45px;
When using 3 values:
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
padding: 30px 60px 45px 85px;
When using 4 values:
To remember the order, start at the top and go clockwise.
Defines the width of the element.
default
width: auto;
The element will automatically adjust its width to allow its content to be displayed correctly.
width: 240px;
You can use numeric values like pixels, (r)em, percentages...
width: 50%;
If you use percentages, the value is relative to the container's width.
Like border-width
, but for the bottom border only.
默认属性
border-bottom-width: 0;
Removes the bottom border.
border-bottom-width: 4px;
You can use pixel values.
Like border-width
, but for the left border only.
默认属性
border-left-width: 0;
Removes the left border.
border-left-width: 4px;
You can use pixel values.
Like border-width
, but for the right border only.
默认属性
border-right-width: 0;
Removes the right border.
border-right-width: 4px;
You can use pixel values.
Like border-width
, but for the top border only.
默认属性
border-top-width: 0;
Removes the top border.
border-top-width: 4px;
You can use pixel values.
Defines the width of the element's borders.
border-width: 1px;
Defines the width of all borders to 1px.
border-width: 2px 0;
Defines the top and bottom borders to 2px, the left and right to 0.
Defines how the width and height of the element are calculated: whether they include the padding and borders or not.
默认属性
box-sizing: content-box;
The width and height of the element only apply to the content of the element.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
The full width is 24px + 60px + 200px = 284px.
The content has the defined width. The box accomodates for those dimensions.
box-sizing: border-box;
The width and height of the element apply to all parts of the element: the content, the padding and the borders.
For example, this element has
border-width: 12px
padding: 30px
width: 200px
The full width is 200px, no matter what.
The box has the defined width. The content accomodates for those dimensions, and ends up being 200px - 60px - 24px = 116px.
Defines the height of the element.
默认属性
height: auto;
The element will automatically adjust its height to allow its content to be displayed correctly.
height: 100px;
You can use numeric values like pixels, (r)em, percentages...
If the content does not fit within the specified height, it will overflow. How the container will handle this overflowing content is defined by the overflow
property.
Defines the height of a single line of text.
默认属性
line-height: normal;
Reverts to the default value of the browser.
recommended
line-height: 1.6;
You can use unitless values: the line height will be relative to the font size.
line-height: 30px;
You can use pixel values.
line-height: 0.8em;
You can use em values: like with unitless values, the line height will be relative to the font size.
Defines the space outside the element, on the bottom side.
默认属性
margin-bottom: 0;
Removes any margin at the bottom.
margin-bottom: 30px;
You can use pixel values.
margin-bottom: 2em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-bottom: 10%;
You can use percentage values.
The percentage is based on the width of the container.
Defines the space outside the element, on the left side.
默认属性
margin-left: 0;
Removes any margin on the left.
margin-left: 50px;
You can use pixel values.
margin-left: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-left: 30%;
You can use percentage values.
The percentage is based on the width of the container.
margin-left: auto;
The auto keyword will give the left side a share of the remaining space.
When combined with margin-right: auto
, it will center the element, if a fixed width is defined.
Defines the space outside the element, on the right side.
默认属性
margin-right: 0;
Removes any margin on the right.
margin-right: 50px;
You can use pixel values.
margin-right: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-right: 30%;
You can use percentage values.
The percentage is based on the width of the container.
margin-right: auto;
The auto keyword will give the right side a share of the remaining space.
When combined with margin-left: auto
, it will center the element, if a fixed width is defined.
Defines the space outside the element, on the top side.
默认属性
margin-top: 0;
Removes any margin at the top.
margin-top: 30px;
You can use pixel values.
margin-top: 2em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizemargin-top: 10%;
You can use percentage values.
The percentage is based on the width of the container.
Shorthand property for margin-top
margin-right
margin-bottom
and margin-left
.
默认属性
margin: 0;
Removes all margins.
margin: 30px;
When using 1 value, the margin is set for all 4 sides.
margin: 30px 60px;
When using 2 values:
To remember the order think about the values you haven't defined.
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
margin: 30px 60px 45px;
When using 3 values:
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
margin: 30px 60px 45px 85px;
When using 4 values:
To remember the order, start at the top and go clockwise.
Defines the maximum height the element can be.
默认属性
max-height: none;
The element has no limit in terms of height.
max-height: 2000px;
You can use numeric values like pixels, (r)em, percentages...
If the maximum height is larger than the element's actual height, the max height has no effect.
max-height: 100px;
If the content does not fit within the maximum height, it will overflow. How the container will handle this overflowing content is defined by the overflow
property.
Defines the maximum width the element can be.
默认属性
max-width: none;
The element has no limit in terms of width.
max-width: 2000px;
You can use numeric values like pixels, (r)em, percentages...
If the maximum width is larger than the element's actual width, the max width has no effect.
max-width: 150px;
If the content does not fit within the maximum width, it will automatically change the height of the element to accomodate for the wrapping of the content.
Defines the minimum height of the element.
默认属性
min-height: 0;
The element has no minimum height.
min-height: 200px;
You can use numeric values like pixels, (r)em, percentages...
If the minimum height is larger than the element's actual height, the min height will be applied.
min-height: 5px;
If the minimum height is smaller than the element's actual height, the min height has no effect.
Defines the minimum width of the element.
默认属性
min-width: 0;
The element has no minimum width.
min-width: 300px;
You can use numeric values like pixels, (r)em, percentages...
If the minimum width is larger than the element's actual width, the min width will be applied.
min-width: 5px;
If the minimum width is smaller than the element's actual width, the min width has no effect.
Defines the space inside the element, on the bottom side.
默认属性
padding-bottom: 0;
Removes any padding on the bottom.
padding-bottom: 50px;
You can use pixel values.
padding-bottom: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-bottom: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the left side.
默认属性
padding-left: 0;
Removes any padding on the left.
padding-left: 50px;
You can use pixel values.
padding-left: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-left: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the right side.
默认属性
padding-right: 0;
Removes any padding on the right.
padding-right: 50px;
You can use pixel values.
padding-right: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-right: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Defines the space inside the element, on the top side.
默认属性
padding-top: 0;
Removes any padding on the top.
padding-top: 50px;
You can use pixel values.
padding-top: 7em;
You can use (r)em values.
The value is relative to the font size:
<html>
the root element's font sizepadding-top: 30%;
You can use percentage values.
The percentage is based on the width of the element.
Shorthand property for padding-top
padding-right
padding-bottom
and padding-left
.
默认属性
padding: 0;
Removes all paddings.
padding: 30px;
When using 1 value, the padding is set for all 4 sides.
padding: 30px 60px;
When using 2 values:
To remember the order think about the values you haven't defined.
If you enter 2 values (top/right), you omit setting bottom and left. Because bottom is the vertical counterpart of top, it will use top’s value. And because left is the horizontal counterpart of right, it will use right’s value.
padding: 30px 60px 45px;
When using 3 values:
To remember the order think about the values you haven't defined.
If you enter 3 values (top/right/bottom), you omit setting left. As right’s counterpart, it will use its value.
padding: 30px 60px 45px 85px;
When using 4 values:
To remember the order, start at the top and go clockwise.
Defines the width of the element.
默认属性
width: auto;
The element will automatically adjust its width to allow its content to be displayed correctly.
width: 240px;
You can use numeric values like pixels, (r)em, percentages...
width: 50%;
If you use percentages, the value is relative to the container's width.
Defines how each line is aligned within a flexbox container. It only applies if flex-wrap: wrap
is present, and if there are multiple lines of flexbox items.
default
align-content: stretch;
Each line will stretch to fill the remaining space.
In this case, the container is 300px
high. All boxes are 50px
high, apart from the second one who is 100px
high.
This remaining space is distributed equally amongst the two lines:
align-content: flex-start;
Each line will only fill the space it needs. They will all move towards the start of the flexbox container's cross axis.
align-content: flex-end;
Each line will only fill the space it needs. They will all move towards the end of the flexbox container's cross axis.
align-content: center;
Each line will only fill the space it needs. They will all move towards the center of the flexbox container's cross axis.
align-content: space-between;
Each line will only fill the space it needs. The remaining space will appear between the lines.
align-content: space-around;
Each line will only fill the space it needs. The remaining space will be distributed equally around the lines: before the first line, between the two, and after the last one.
Defines how flexbox items are aligned according to the cross axis, within a line of a flexbox container.
align-items: flex-start;
The flexbox items are aligned at the start of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will be aligned vertically at the top.
align-items: flex-end;
The flexbox items are aligned at the end of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will be aligned vertically at the bottom.
align-items: center;
The flexbox items are aligned at the center of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will be centered vertically.
align-items: baseline;
The flexbox items are aligned at the baseline of the cross axis.
By default, the cross axis is vertical. This means the flexbox items will align themselves in order to have the baseline of their text align along a horizontal line.
align-items: stretch;
The flexbox items will stretch across the whole cross axis.
By default, the cross axis is vertical. This means the flexbox items will fill up the whole vertical space.
Works like align-items
, but applies only to a single flexbox item, instead of all of them.
default
align-self: auto;
The target will use the value of align-items
.
align-self: flex-start;
If the container has align-items: center
and the target has align-self: flex-start
, only the target will be at the start of the cross axis.
By default, this means it will be aligned vertically at the top.
align-self: flex-end;
If the container has align-items: center
and the target has align-self: flex-end
, only the target will be at the end of the cross axis.
By default, this means it will be aligned vertically at the bottom.
align-self: center;
If the container has align-items: flex-start
and the target has align-self: center
, only the target will be at the center of the cross axis.
By default, this means it will be vertically centered.
align-self: baseline;
If the container has align-items: center
and the target has align-self: baseline
, only the target will be at the baseline of the cross axis.
By default, this means it will be aligned along the basline of the text.
align-self: stretch;
If the container has align-items: center
and the target has align-self: stretch
, only the target will stretch along the whole cross axis.
Defines the initial size of a flexbox item.
default
flex-basis: auto;
The element will be automatically sized based on its content, or on any height
or width
value if they are defined.
flex-basis: 80px;
You can define pixel or (r)em values. The element will wrap its content to avoid any overflow.
Defines how flexbox items are ordered within a flexbox container.
default
flex-direction: row;
The flexbox items are ordered the same way as the text direction, along the main axis.
flex-direction: row-reverse;
The flexbox items are ordered the opposite way as the text direction, along the main axis.
flex-direction: column;
The flexbox items are ordered the same way as the text direction, along the cross axis.
flex-direction: column-reverse;
The flexbox items are ordered the opposite way as the text direction, along the cross axis.
Shorthand property for flex-direction
and flex-wrap
.
Defines how much a flexbox item should grow if there's space available.
default
flex-grow: 0;
The element will not grow if there's space available. It will only use the space it needs.
flex-grow: 1;
The element will grow by a factor of 1. It will fill up the remaining space if no other flexbox item has a flex-grow
value.
flex-grow: 2;
Because the flex-grow value is relative, its behaviour depends on the value of the flexbox item siblings.
In this example, the remaining space is divided in 3:
Defines how much a flexbox item should shrink if there's not enough space available.
default
flex-shrink: 1;
If there's not enough space available in the container's main axis, the element will shrink by a factor of 1, and will wrap its content.
flex-shrink: 0;
The element will not shrink: it will retain the width it needs, and not wrap its content. Its siblings will shrink to give space to the target element.
Because the target element will not wrap its content, there is a chance for the flexbox container's content to overflow.
flex-shrink: 2;
Because the flex-shrink value is relative, its behaviour depends on the value of the flexbox item siblings.
In this example, the green item wants to fill 100% of the width. The space it needs is taken from its two siblings, and is divided in 4:
Defines if flexbox items appear on a single line or on multiple lines within a flexbox container.
default
flex-wrap: nowrap;
The flexbox items will remain on a single line, no matter what, and will eventually overflow if needed.
flex-wrap: wrap;
The flexbox items will be distributed among multiple lines if needed.
flex-wrap: wrap-reverse;
The flexbox items will be distributed among multiple lines if needed. Any additional line will appear before the previous one.
Defines how flexbox items are aligned according to the main axis, within a flexbox container.
default
justify-content: flex-start;
The flexbox items are pushed towards the start of the container's main axis.
justify-content: flex-end;
The flexbox items are pushed towards the end of the container's main axis.
justify-content: center;
The flexbox items are centered along the container's main axis.
justify-content: space-between;
The remaining space is distributed between the flexbox items.
justify-content: space-around;
The remaining space is distributed around the flexbox items: this adds space before the first item and after the last one.
Defines the order of a flexbox item.
default
order: 0;
The order of the flexbox items is the one defined in the HTML code.
order: 1;
The order is relative to the flexbox item's siblings. The final order is defined when all individual flexbox item order values are taken into account.
order: -1;
You can use negative values.
order: 9;
You can set a different value for each flexbox item.
定义 flexbox 容器中每一行的对齐方式。此属性仅当预先设置了 flex-wrap: wrap
后有效,且 flexbox 的子元素有多行。
默认属性
align-content: stretch;
每一行拉伸平分并填充剩余空间
+此示例中,容器高为 300px
。 所有的方块高 50px
,除了第二个的高度为 100px
。
剩余空间被两行平分:
+align-content: flex-start;
每一行仅仅占用实际所需的空间。所有的元素都将靠纵向轴起始处对齐。
+align-content: flex-end;
每一行仅仅占用实际所需的空间。所有的元素都将靠纵向轴末尾处对齐。
+align-content: center;
每一行仅仅占用实际所需的空间。所有的元素都将靠纵向轴中间对齐。
+align-content: space-between;
每一行仅仅占用实际所需的空间。剩余空间占据行之间。
+align-content: space-around;
每一行仅仅占用实际所需的空间。剩余空间平均分配给行元素之间(上下)。
+定义了在 flexbox 容器的一行内,子元素在纵向轴的对齐方式。
+align-items: flex-start;
flexbox 的子元素按照纵向轴的起始处对齐。
+默认,纵向轴是垂直的,所以这就意味着 flexbox 的子元素对齐于垂直方向的顶部。
+align-items: flex-end;
flexbox 的子元素按照纵向轴的末尾处对齐。
+默认,纵向轴是垂直的,所以这就意味着 flexbox 的子元素对齐于垂直方向的底部。
+align-items: center;
flexbox 的子元素按照纵向轴的中间对齐。
+默认,纵向轴是垂直的,所以这就意味着 flexbox 的子元素对齐于垂直方向的中间。
+align-items: baseline;
flexbox 的子元素按照纵向轴的 baseline 对齐。
+默认,纵向轴是垂直的,所以这就意味着 flexbox 的子元素对齐于以自身文字为横向水平线的baseline。
+align-items: stretch;
flexbox 的子元素将拉伸覆盖整个纵向轴。
+默认,纵向轴是垂直的,所以这就意味着 flexbox 的子元素将填满整个纵向的空间。
+原理如同 align-items
,但是仅仅作用于一个 flexbox 元素,而不是作用于所有的元素
+ 默认属性
+
+
+ align-self: auto;
+
元素使用 align-items
的值。
+
+
+ align-self: flex-start;
+
如果容器有属性 align-items: center
且 目标元素 有属性 align-self: flex-start
,那么仅仅目标元素对齐于纵向轴的起始处。
默认,这就意味着元素对齐于垂直方向的顶部。
+
+
+
+ align-self: flex-end;
+
如果容器有属性 align-items: center
且 目标元素 有属性 align-self: flex-end
,那么仅仅目标元素对齐于纵向轴的末尾处。
默认,这就意味着元素对齐于垂直方向的底部。
+
+
+
+ align-self: center;
+
如果容器有属性 align-items: flex-start
且 目标元素 有属性 align-self: center
,那么仅仅目标元素对齐于纵向轴的中间。
默认,这就意味着元素对齐于垂直方向的中间。
+
+
+
+ align-self: baseline;
+
如果容器有属性 align-items: center
且 目标元素 有属性 align-self: baseline
,那么仅仅目标元素对齐于纵向轴的 baseline。
默认,这就意味着元素沿着文字的 baseline 对齐。
+
+
+
+ align-self: stretch;
+
如果容器有属性 align-items: center
且 目标元素 有属性 align-self: stretch
,那么仅仅目标元素拉伸填充于整个纵向轴。
定义 flexbox 的初始化大小。
+ +
+ 默认属性
+
+
+ flex-basis: auto;
+
元素根据自身的内容自动调整大小,或者根据已定义的 高度
或 宽度
调整大小。
+
+
+ flex-basis: 80px;
+
你可以定义 pixel 或 (r)em 值。元素将换行其内容避开任何的元素溢出。
+ +定义了元素在 flexbox 容器中的排序方式。
+ +
+ 默认属性
+
+
+ flex-direction: row;
+
元素按照与文字方向(书写模式)相同的方向,沿着主(横)轴。
+ +
+
+
+ flex-direction: row-reverse;
+
元素按照与文字方向(书写模式)相反的方向,沿着主(横)轴。
+
+
+
+ flex-direction: column;
+
元素按照与文字方向(书写模式)相同的方向,沿着纵向轴。
+
+
+
+ flex-direction: column-reverse;
+
元素按照与文字方向(书写模式)相反的方向,沿着纵向轴。
+是 flex-direction
和 flex-wrap
的缩写形式。
定义了元素当有可用空间的时候如何 占用。
+ +
+ 默认属性
+
+
+ flex-grow: 0;
+
元素 不 不占用剩余空间。它仅仅占用自身所需空间。
+ +
+
+
+ flex-grow: 1;
+
元素将 占用 扩展因子 1。如果没有其他元素也设置了 flex-grow
的话,它将占用剩下的所有空间。
+
+
+ flex-grow: 2;
+
因为 flex-grow 的值是相对的,它的具体表现还取决于此元素的同级元素。
+在这个例子中,剩余空间被分隔成了 3 个扩展因子:
+定义了当没有足够空间的时候,元素如何压缩自身空间。
+ +
+ 默认属性
+
+
+ flex-shrink: 1;
+
当主轴(横向轴)没有足够空间的时候,元素将按照扩展因子 1 来进行压缩,也将导致换行(折叠)其自身的内容。
+ +
+
+
+ flex-shrink: 0;
+
元素不压缩:占用它所需要的宽且不换行(折叠)自身的内容。同级元素将压缩给出目标元素足够的控件。
+因为目标元素不换行(折叠)自身的内容,所以可能会导致 flexbox 容器的内容产生元素移除。
+ +
+
+
+ flex-shrink: 2;
+
因为 flex-shrink 的值是相对的,它的具体表现还取决于此元素的同级元素。
+在此例子中,绿色的元素占用了 100% 的宽度。此部分的空间将从它的两个同级元素中占用,并且占用被分成了 4份:
+定义了元素在 flexbox 容器中是显示一行还是多行。
+ +
+ 默认属性
+
+
+ flex-wrap: nowrap;
+
元素将始终保持单行,最终,如果需要将会进行元素溢出。
+ +
+
+
+ flex-wrap: wrap;
+
元素将根据实际情况分布在多行。
+ +
+
+
+ flex-wrap: wrap-reverse;
+
元素将根据实际情况分布在多行。任何新增的行都将会被添加在之前的一行之前。
+定义了在 flexbox 容器中,元素沿着主轴(横向轴)的对齐情况。
+ +
+ 默认属性
+
+
+ justify-content: flex-start;
+
元素朝着主轴(横向轴)的开始方向排列。
+ +
+
+
+ justify-content: flex-end;
+
元素朝着主轴(横向轴)的末尾方向排列。
+ +
+
+
+ justify-content: center;
+
元素朝着主轴(横向轴)的中间排列。
+ +
+
+
+ justify-content: space-between;
+
剩余的空间平均分布在元素之间。
+ +
+
+
+ justify-content: space-around;
+
剩余的空间平均分布在元素的开始和结束处:在第一个元素的前面和最后一个元素的后面也分配空间。
+ +定义元素的排序。
+ +
+ 默认属性
+
+
+ order: 0;
+
元素的排序按照其 HTML 代码中的排序。
+ +
+
+
+ order: 1;
+
元素的排序与其同级元素具有相关性。最终的排序将会考虑到所有元素的排序值。
+ +
+
+
+ order: -1;
+
值你可以使用负数。
+ +
+
+
+ order: 9;
+
你可以为每一个元素设置不同的值。
+ +Defines the position of the element according to its bottom edge.
default
bottom: auto;
The element will remain in its natural position.
bottom: 20px;
If the element is in position relative, the element will move upwards by the amount defined by the bottom value.
bottom: 0;
If the element is in position absolute, the element will position itself from the bottom of the first positioned ancestor.
Defines the position of the element according to its left edge.
default
left: auto;
The element will remain in its natural position.
left: 80px;
If the element is in position relative, the element will move left by the amount defined by the left value.
left: -20px;
If the element is in position absolute, the element will position itself from the left of the first positioned ancestor.
Defines the position behavior of the element.
default
position: static;
The element will remain in the natural flow of the page.
As a result, it will not act as anchor point for the absolutely positioned pink block.
Also, it will not react to the following properties:
top
bottom
left
right
z-index
position: relative;
The element will remain in the natural flow of the page.
It also makes the element positioned: it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
position: absolute;
The element will not remain in the natural flow of the page. It will position itself according to the closest positioned ancestor.
Because it's positioned, it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
position: fixed;
The element will not remain in the natural flow of the page. It will position itself according to the viewport.
Because it's positioned, it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
Defines the position of the element according to its right edge.
default
right: auto;
The element will remain in its natural position.
right: 80px;
If the element is in position relative, the element will move right by the amount defined by the right value.
right: -20px;
If the element is in position absolute, the element will position itself from the right of the first positioned ancestor.
Defines the position of the element according to its top edge.
default
top: auto;
The element will remain in its natural position.
top: 20px;
If the element is in position relative, the element will move downwards by the amount defined by the top value.
top: 0;
If the element is in position absolute, the element will position itself from the top of the first positioned ancestor.
Defines the order of the elements on the z-axis. It only works on positioned elements (anything apart from static
).
default
z-index: auto;
The order is defined by the order in the HTML code:
z-index: 1;
The z-index value is relative to the other ones. The target element is move in front of its siblings.
z-index: -1;
You can use negative values. The target element is move in behind its siblings.
Defines the position of the element according to its bottom edge.
默认属性
bottom: auto;
The element will remain in its natural position.
bottom: 20px;
If the element is in position relative, the element will move upwards by the amount defined by the bottom value.
bottom: 0;
If the element is in position absolute, the element will position itself from the bottom of the first positioned ancestor.
Defines the position of the element according to its left edge.
默认属性
left: auto;
The element will remain in its natural position.
left: 80px;
If the element is in position relative, the element will move left by the amount defined by the left value.
left: -20px;
If the element is in position absolute, the element will position itself from the left of the first positioned ancestor.
Defines the position behavior of the element.
默认属性
position: static;
The element will remain in the natural flow of the page.
As a result, it will not act as anchor point for the absolutely positioned pink block.
Also, it will not react to the following properties:
top
bottom
left
right
z-index
position: relative;
The element will remain in the natural flow of the page.
It also makes the element positioned: it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
position: absolute;
The element will not remain in the natural flow of the page. It will position itself according to the closest positioned ancestor.
Because it's positioned, it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
position: fixed;
The element will not remain in the natural flow of the page. It will position itself according to the viewport.
Because it's positioned, it will act as an anchor point for the absolutely positioned pink block.
Also, it will react to the following properties:
top
bottom
left
right
z-index
Defines the position of the element according to its right edge.
默认属性
right: auto;
The element will remain in its natural position.
right: 80px;
If the element is in position relative, the element will move right by the amount defined by the right value.
right: -20px;
If the element is in position absolute, the element will position itself from the right of the first positioned ancestor.
Defines the position of the element according to its top edge.
默认属性
top: auto;
The element will remain in its natural position.
top: 20px;
If the element is in position relative, the element will move downwards by the amount defined by the top value.
top: 0;
If the element is in position absolute, the element will position itself from the top of the first positioned ancestor.
Defines the order of the elements on the z-axis. It only works on positioned elements (anything apart from static
).
默认属性
z-index: auto;
The order is defined by the order in the HTML code:
z-index: 1;
The z-index value is relative to the other ones. The target element is move in front of its siblings.
z-index: -1;
You can use negative values. The target element is move in behind its siblings.
Defines how long the transition has to wait before starting.
default
transition-delay: 0s;
The transition will wait zero seconds, and thus start right away.
transition-delay: 1.2s;
You can use decimal values in seconds with the keyword s
.
transition-delay: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
transition-delay: -500ms;
You can use negative values: the transition will start as if it had already been playing for 500ms
.
Defines how long the transition lasts.
default
transition-duration: 0s;
The transition will last zero seconds, and is thus instant.
transition-duration: 1.2s;
You can use decimal values in seconds with the keyword s
.
transition-duration: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
Defines which properties will transition.
default
transition-property: all;
The element will transition all properties:
transition-property: none;
The element will transition no property: the transition is thus instant.
transition-property: background;
The element will only transtion the background property.
transition-property: color;
The element will only transtion the color property.
transition-property: transform;
The element will only transtion the transform property.
Defines how the values between the start and the end of the transition are calculated.
default
transition-timing-function: ease;
The transition starts slowly, accelerates in the middle, and slows down at the end.
transition-timing-function: ease-in;
The transition starts slowly, and accelerates gradually until the end.
transition-timing-function: ease-out;
The transition starts quickly, and decelerates gradually until the end.
transition-timing-function: ease-in-out;
Like ease
, but more pronounced.
The transition starts quickly, and decelerates gradually until the end.
transition-timing-function: linear;
The transition has a *constant speed.
transition-timing-function: step-start;
The transition jumps instantly to the final state.
transition-timing-function: step-end;
The transition stays at the initial state until the end, when it instantly jumps to the final state.
transition-timing-function: steps(4, end);
By using steps()
with an integer, you can define a specific number of steps before reaching the end. The state of the element will not vary gradually, but rather jump from state to state in separate instants.
Shorthand property for transition-property
transition-duration
transition-timing-function
and transition-delay
.
Only transition-duration
is required.
transition: 1s;
transition-duration
is set to 1s
transition-property
defaults to all
transition-timing-function
defaults to ease
transition-delay
defaults to 0s
transition: 1s linear;
transition-duration
is set to 1s
transition-property
defaults to all
transition-timing-function
is set to linear
transition-delay
defaults to 0s
transition: background 1s linear;
transition-duration
is set to 1s
transition-property
is set to background
transition-timing-function
is set to linear
transition-delay
defaults to 0s
transition: background 1s linear 500ms;
transition-duration
is set to 1s
transition-property
is set to background
transition-timing-function
is set to linear
transition-delay
is set to 500ms
transition: background 4s, transform 1s;
You can combine multiple properties with their own transition duration.
Defines how long the transition has to wait before starting.
默认属性
transition-delay: 0s;
The transition will wait zero seconds, and thus start right away.
transition-delay: 1.2s;
You can use decimal values in seconds with the keyword s
.
transition-delay: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
transition-delay: -500ms;
You can use negative values: the transition will start as if it had already been playing for 500ms
.
Defines how long the transition lasts.
默认属性
transition-duration: 0s;
The transition will last zero seconds, and is thus instant.
transition-duration: 1.2s;
You can use decimal values in seconds with the keyword s
.
transition-duration: 2400ms;
You can use milliseconds instead of seconds, with the keyword ms
.
Defines which properties will transition.
默认属性
transition-property: all;
The element will transition all properties:
transition-property: none;
The element will transition no property: the transition is thus instant.
transition-property: background;
The element will only transtion the background property.
transition-property: color;
The element will only transtion the color property.
transition-property: transform;
The element will only transtion the transform property.
Defines how the values between the start and the end of the transition are calculated.
默认属性
transition-timing-function: ease;
The transition starts slowly, accelerates in the middle, and slows down at the end.
transition-timing-function: ease-in;
The transition starts slowly, and accelerates gradually until the end.
transition-timing-function: ease-out;
The transition starts quickly, and decelerates gradually until the end.
transition-timing-function: ease-in-out;
Like ease
, but more pronounced.
The transition starts quickly, and decelerates gradually until the end.
transition-timing-function: linear;
The transition has a *constant speed.
transition-timing-function: step-start;
The transition jumps instantly to the final state.
transition-timing-function: step-end;
The transition stays at the initial state until the end, when it instantly jumps to the final state.
transition-timing-function: steps(4, end);
By using steps()
with an integer, you can define a specific number of steps before reaching the end. The state of the element will not vary gradually, but rather jump from state to state in separate instants.
Shorthand property for transition-property
transition-duration
transition-timing-function
and transition-delay
.
Only transition-duration
is required.
transition: 1s;
transition-duration
is set to 1s
transition-property
defaults to all
transition-timing-function
defaults to ease
transition-delay
defaults to 0s
transition: 1s linear;
transition-duration
is set to 1s
transition-property
defaults to all
transition-timing-function
is set to linear
transition-delay
defaults to 0s
transition: background 1s linear;
transition-duration
is set to 1s
transition-property
is set to background
transition-timing-function
is set to linear
transition-delay
defaults to 0s
transition: background 1s linear 500ms;
transition-duration
is set to 1s
transition-property
is set to background
transition-timing-function
is set to linear
transition-delay
is set to 500ms
transition: background 4s, transform 1s;
You can combine multiple properties with their own transition duration.
Defines the color of the text.
color: transparent;
Applies a transparent color to the text. The text will still take up the space it should.
color: red;
You can use one of the 140+ color names.
color: #05ffb0;
You can use hexadecimal color codes.
color: rgb(50, 115, 220);
You can use rgb() color codes:
red
green
blue
Each of them can have a value between 0 and 255.
color: rgba(0, 0, 0, 0.5);
You can use rgba() color codes:
rgb
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
color: hsl(14, 100%, 53%);
You can use hsl() color codes:
hue
and can go from 0 to 359saturation
and go from 0% to 100%luminosity
and go from 0% to 100%color: hsla(14, 100%, 53%, 0.6);
You can use hsl()a color codes:
hsl
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
font-family: "Source Sans Pro", "Arial", sans-serif;
When using multiple values, the font-family
list of font families defines the priority in which the browser should choose the font family.
The browser will look for each family on the user's computer and in any @font-face resource.
The list is prioritized from left to right: it will use the first value if it's available, or go to the next one, until the end of the list is reached. The default font family is defined by the browser preferences.
In this example, the browser will try to use Source Sans Pro
if it's available. If it can't find it, it will try to use Arial
. If it's not available either, it will use the browser's sans-serif
font.
font-family: serif;
The browser will use a serif font family: all characters have stroke endings.
font-family: sans-serif;
The browser will use a sans-serif font family: no character has stroke endings.
font-family: monospace;
The browser will use a monospace font family: all characters have the same width.
font-family: cursive;
The browser will use a cursive font family.
font-family: fantasy;
The browser will use a fantasy font family.
Defines the size of the text.
default
font-size: medium;
The text will use the browser's default medium size.
font-size: 20px;
You can use pixel values.
font-size: 1.2em;
You can use em values.
The value is relative to the parent's font-size
.
As a result, the value will cascade if used on child elements.
font-size: 1.2rem;
You can use rem values.
The value is relative to the root element's font-size
, which is the <html>
element.
As a result, the value will not vary depending on the depth of the element in the HTML hierarchy, and will reamin context independent.
font-size: 90%;
You can use percentage values. They act like em values.
The value is relative to the parent's font-size
.
As a result, the value will cascade if used on child elements.
font-size: smaller;
You can use relative keywords. The value is relative to the parent.
The following are available:
larger
smaller
font-size: x-large;
You can use absolute keywords. The value is relative to the root element <html>
.
The following are available:
xx-small
x-small
small
medium
large
x-large
xx-large
Defines how much the text is slanted.
default
font-style: normal;
The text is not slanted.
font-style: italic;
Use the italic version of the font: the letters are slightly slanted.
font-style: oblique;
Use the oblique version of the font: the letters are more slanted than italic.
Defines which glyph to use for each letter.
default
font-variant: normal;
Each letter uses its normal glyph.
font-variant: small-caps;
Each letter uses its small capitalized version.
Defines the weight of the text.
default
font-weight: normal;
The text is in normal weight.
font-weight: bold;
The text becomes bold.
font-weight: 600;
You can use numeric values. They all correspond to a particular named weight:
If the font family doesn't provide the requested weight, it will use the closest available one.
font-weight: lighter;
You can use relative keywords: lighter
or bolder
. The browser will use the next available weight.
Shorthand property for font-style
font-variant
font-weight
font-size
line-height
and font-family
.
Defines the spacing between the characters of a block of text.
default
letter-spacing: normal;
The spacing between the characters is normal.
letter-spacing: 2px;
You can use pixel values.
letter-spacing: 0.1em;
You can use em values: this allows the spacing to remain relative to the font-size.
Defines the height of a single line of text.
default
line-height: normal;
Reverts to the default value of the browser.
recommended
line-height: 1.6;
You can use unitless values: the line height will be relative to the font size.
line-height: 30px;
You can use pixel values.
line-height: 0.8em;
You can use em values: like with unitless values, the line height will be relative to the font size.
Defines how the text content of the element is horizontally aligned.
text-align: left;
The text content is aligned to the left.
text-align: right;
The text content is aligned to the right.
text-align: center;
The text content is centered.
text-align: justify;
The text content is justified.
Defines how the text content of the element is decorated.
default
text-decoration: none;
Removes any text decoration.
text-decoration: underline;
Underlines the text content.
Defines the indentation of the element's first line of text.
default
text-indent: 0;
The text is not indented.
text-indent: 40px;
You can use numeric values like pixels, (r)em, percentages...
Notice how only the first line is indented.
text-indent: -2em;
You can also use negative values.
Defines how the hidden text content behaves if it's overflowing.
default
text-overflow: clip;
The text content is clipped and not accessible.
text-overflow: ellipsis;
The overflowing content is replaced by an ellipsis: …
Defines the shadow of the text content.
default
text-shadow: none;
The text content has no shadow.
text-shadow: 2px 6px;
You need at least two values:
The shadow color will be inherited from the text color.
text-shadow: 2px 6px red;
You can define a color as the last value.
As with color
, you can use color names, hexadecimal, rgb, hsl...
text-shadow: 2px 4px 10px red;
The optional third value defines the blur of the shadow.
The color will be diffused across 10px in this example, from opaque to transparent.
Defines how the text content should be transformed.
default
text-transform: none;
Removes any text transformation: the text will appear the same as in the HTML code.
text-transform: capitalize;
Turns the first letter of each word into a capital letter.
text-transform: uppercase;
Turns all letters into capital letters.
text-transform: lowercase;
Turns all letters into lowercase letters.
Defines how the element's white space is handled.
default
white-space: normal;
Sequences of spaces are combined into one.
Line breaks are ignored.
The text content is wrapped.
white-space: nowrap;
Sequences of spaces are combined into one.
Line breaks are ignored.
The text content is not wrapped and remains on a single line.
white-space: pre;
The white space is exactly preserved.
<br>
white-space: pre-wrap;
The white space is mostly preserved.
<br>
, but also when reaching the end of the elementwhite-space: pre-line;
Only new lines are preserved.
<br>
, but also when reaching the end of the elementDefines how words should break when reaching the end of a line.
default
word-break: normal;
Words with no space will not break. Sequences of uninterrupted characters will be displayed on a single line.
word-break: break-all;
Words with no space will break as soon as they reach the end of a line.
Defines the spacing between words of a block of text.
default
word-spacing: normal;
The spacing between the characters is normal.
word-spacing: 5px;
You can use pixel values.
word-spacing: 2em;
You can use em values: this allows the spacing to remain relative to the font-size.
Defines the color of the text.
color: transparent;
Applies a transparent color to the text. The text will still take up the space it should.
color: red;
You can use one of the 140+ color names.
color: #05ffb0;
You can use hexadecimal color codes.
color: rgb(50, 115, 220);
You can use rgb() color codes:
red
green
blue
Each of them can have a value between 0 and 255.
color: rgba(0, 0, 0, 0.5);
You can use rgba() color codes:
rgb
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
color: hsl(14, 100%, 53%);
You can use hsl() color codes:
hue
and can go from 0 to 359saturation
and go from 0% to 100%luminosity
and go from 0% to 100%color: hsla(14, 100%, 53%, 0.6);
You can use hsl()a color codes:
hsl
alpha
channel and defines the opacity of the colorThe alpha value can go from zero 0 (transparent) to one 1 (opaque).
font-family: "Source Sans Pro", "Arial", sans-serif;
When using multiple values, the font-family
list of font families defines the priority in which the browser should choose the font family.
The browser will look for each family on the user's computer and in any @font-face resource.
The list is prioritized from left to right: it will use the first value if it's available, or go to the next one, until the end of the list is reached. The default font family is defined by the browser preferences.
In this example, the browser will try to use Source Sans Pro
if it's available. If it can't find it, it will try to use Arial
. If it's not available either, it will use the browser's sans-serif
font.
font-family: serif;
The browser will use a serif font family: all characters have stroke endings.
font-family: sans-serif;
The browser will use a sans-serif font family: no character has stroke endings.
font-family: monospace;
The browser will use a monospace font family: all characters have the same width.
font-family: cursive;
The browser will use a cursive font family.
font-family: fantasy;
The browser will use a fantasy font family.
Defines the size of the text.
默认属性
font-size: medium;
The text will use the browser's default medium size.
font-size: 20px;
You can use pixel values.
font-size: 1.2em;
You can use em values.
The value is relative to the parent's font-size
.
As a result, the value will cascade if used on child elements.
font-size: 1.2rem;
You can use rem values.
The value is relative to the root element's font-size
, which is the <html>
element.
As a result, the value will not vary depending on the depth of the element in the HTML hierarchy, and will reamin context independent.
font-size: 90%;
You can use percentage values. They act like em values.
The value is relative to the parent's font-size
.
As a result, the value will cascade if used on child elements.
font-size: smaller;
You can use relative keywords. The value is relative to the parent.
The following are available:
larger
smaller
font-size: x-large;
You can use absolute keywords. The value is relative to the root element <html>
.
The following are available:
xx-small
x-small
small
medium
large
x-large
xx-large
Defines how much the text is slanted.
默认属性
font-style: normal;
The text is not slanted.
font-style: italic;
Use the italic version of the font: the letters are slightly slanted.
font-style: oblique;
Use the oblique version of the font: the letters are more slanted than italic.
Defines which glyph to use for each letter.
默认属性
font-variant: normal;
Each letter uses its normal glyph.
font-variant: small-caps;
Each letter uses its small capitalized version.
Defines the weight of the text.
默认属性
font-weight: normal;
The text is in normal weight.
font-weight: bold;
The text becomes bold.
font-weight: 600;
You can use numeric values. They all correspond to a particular named weight:
If the font family doesn't provide the requested weight, it will use the closest available one.
font-weight: lighter;
You can use relative keywords: lighter
or bolder
. The browser will use the next available weight.
Shorthand property for font-style
font-variant
font-weight
font-size
line-height
and font-family
.
Defines the spacing between the characters of a block of text.
默认属性
letter-spacing: normal;
The spacing between the characters is normal.
letter-spacing: 2px;
You can use pixel values.
letter-spacing: 0.1em;
You can use em values: this allows the spacing to remain relative to the font-size.
Defines the height of a single line of text.
默认属性
line-height: normal;
Reverts to the default value of the browser.
recommended
line-height: 1.6;
You can use unitless values: the line height will be relative to the font size.
line-height: 30px;
You can use pixel values.
line-height: 0.8em;
You can use em values: like with unitless values, the line height will be relative to the font size.
Defines how the text content of the element is horizontally aligned.
text-align: left;
The text content is aligned to the left.
text-align: right;
The text content is aligned to the right.
text-align: center;
The text content is centered.
text-align: justify;
The text content is justified.
Defines how the text content of the element is decorated.
默认属性
text-decoration: none;
Removes any text decoration.
text-decoration: underline;
Underlines the text content.
Defines the indentation of the element's first line of text.
默认属性
text-indent: 0;
The text is not indented.
text-indent: 40px;
You can use numeric values like pixels, (r)em, percentages...
Notice how only the first line is indented.
text-indent: -2em;
You can also use negative values.
Defines how the hidden text content behaves if it's overflowing.
默认属性
text-overflow: clip;
The text content is clipped and not accessible.
text-overflow: ellipsis;
The overflowing content is replaced by an ellipsis: …
Defines the shadow of the text content.
默认属性
text-shadow: none;
The text content has no shadow.
text-shadow: 2px 6px;
You need at least two values:
The shadow color will be inherited from the text color.
text-shadow: 2px 6px red;
You can define a color as the last value.
As with color
, you can use color names, hexadecimal, rgb, hsl...
text-shadow: 2px 4px 10px red;
The optional third value defines the blur of the shadow.
The color will be diffused across 10px in this example, from opaque to transparent.
Defines how the text content should be transformed.
默认属性
text-transform: none;
Removes any text transformation: the text will appear the same as in the HTML code.
text-transform: capitalize;
Turns the first letter of each word into a capital letter.
text-transform: uppercase;
Turns all letters into capital letters.
text-transform: lowercase;
Turns all letters into lowercase letters.
Defines how the element's white space is handled.
默认属性
white-space: normal;
Sequences of spaces are combined into one.
Line breaks are ignored.
The text content is wrapped.
white-space: nowrap;
Sequences of spaces are combined into one.
Line breaks are ignored.
The text content is not wrapped and remains on a single line.
white-space: pre;
The white space is exactly preserved.
<br>
white-space: pre-wrap;
The white space is mostly preserved.
<br>
, but also when reaching the end of the elementwhite-space: pre-line;
Only new lines are preserved.
<br>
, but also when reaching the end of the elementDefines how words should break when reaching the end of a line.
默认属性
word-break: normal;
Words with no space will not break. Sequences of uninterrupted characters will be displayed on a single line.
word-break: break-all;
Words with no space will break as soon as they reach the end of a line.
Defines the spacing between words of a block of text.
默认属性
word-spacing: normal;
The spacing between the characters is normal.
word-spacing: 5px;
You can use pixel values.
word-spacing: 2em;
You can use em values: this allows the spacing to remain relative to the font-size.