Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.

  • Use the :nth-child(odd) or :nth-child(even) pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.
  • Note that you can use it to apply different styles to other HTML elements like div, tr, p, ol, etc.

继续阅读 30秒学会 CSS 片段 – Zebra striped list

Renders a tooltip component.

  • Use the React.useState() hook to create the show variable and initialize it to false.
  • Return a <div> element that contains the <div> that will be the tooltip and the children passed to the component.
  • Handle the onMouseEnter and onMouseLeave methods, by altering the value of the show variable.

继续阅读 30秒学会 React 片段 – Tooltip

Vertically and horizontally centers a child element within its parent element using position: absolute and transform: translate() (as an alternative to flexbox or display: table).
Similar to flexbox, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.

  • position: absolute on the child element allows it to be positioned based on its containing block.
  • left: 50% and top: 50% offsets the child 50% from the left and top edge of its containing block.
  • transform: translate(-50%, -50%) allows the height and width of the child element to be negated so that it is vertically and horizontally centered.
  • Note that the fixed height and width on parent element is for the demo only.

继续阅读 30秒学会 CSS 片段 – Transform centering