Useful Features of CSS
Position
Options:
- static (default)
- relative
- absolute
- fixed
- sticky (CSS3)
The element is positioned according to the normal flow of the document, and then offset relative to its nearest scrolling ancestor and containing block (nearest block-level ancestor), including table-related elements, based on the values of
top,right,bottom, andleft. The offset does not affect the position of any other elements. This value always creates a new stacking context. Note that a sticky element “sticks” to its nearest ancestor that has a “scrolling mechanism” (created whenoverflowishidden,scroll,auto, oroverlay), even if that ancestor isn’t the nearest actually scrolling ancestor. This effectively inhibits any “sticky” behavior (see the GitHub issue on W3C CSSWG).
Demo for sticky: https://mdn.mozillademos.org/zh-CN/docs/Web/CSS/position$samples/Sticky_positioning?revision=1631402
Some attribute related to position
- top, right, bottom, left Only working when position set relative, absolute, sticky or fixed
- z-index
Samples:
- Match Parent(Spinner、Model’s background)
- Why
position: fixedisn’t working in sometimes? - Why
z-indexisn’t working in sometimes?
Overflow
Options:
- auto
- scroll
- hidden
- visible (default)
- overlay
Relative attribute
- overflow-x
- overflow-y
Question:
- What if it set
overflow-x: hiddenandoverflow-y: visible? - Can we use it to highlight columns when hover cells in a table?
- Didn’t
overflow: hiddenworking? - Can we use it to scroll in the table except the header?
Transition
| Default | all 0 ease 0 |
| JavaScript Usage | object.style.transition="width 2s" |
Grammar
transition: property duration timing-function delay;
| Property | Description |
|---|---|
transition-property |
Specifies the name of the CSS property that sets the transition effect. |
transition-duration |
Specifies how many seconds or milliseconds it takes to complete the transition effect. |
transition-timing-function |
Specifies the speed curve of the speed effect. |
transition-delay |
Define when the transition effect starts. |
Samples:
- Expand / collapse elements with transition.
- Transition when elements enter / leave.
CSS Methods
var( <custom-property-name> , <declaration-value>? )
<custom-property-name><declaration-value>
calc( <calc-sum> | <calc-product> | <calc-value> )
Some Other New Features
Color Value Support
rgb(0 0 0) (CSS4)rgba(0 0 0 / 50%) (CSS4)hsl(0deg 0% 0%) (CSS4)hsla(0deg 0% 0% / 50%) (CSS4)

文章评论 ( 0 )