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

Sometimes you need to get access to global document.

To simplify unit-testing, Angular provides it through dependency injection:

import { DOCUMENT } from '@angular/common';
import { Inject } from '@angular/core';

@Component({
  selector: 'my-app',
  template: `<h1>Edit me </h1>`
})
export class AppComponent {

  constructor(@Inject(DOCUMENT) private document: Document) {
    // Word with document.location, or other things here....
  }
}

继续阅读 30秒学会 Angular 片段 – Injecting document

A hook that handles the event of clicking outside of the wrapped component.

  • Create a custom hook that takes a ref and a callback to handle the click event.
  • Use the React.useEffect() hook to append and clean up the click event.
  • Use the React.useRef() hook to create a ref for your click component and pass it to the useClickOutside hook.

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

Uses an SVG shape to separate two different blocks to create more a interesting visual appearance compared to standard horizontal separation.

  • position: relative on the element establishes a Cartesian positioning context for pseudo elements.
  • :after defines a pseudo element.
  • background-image: url(...) adds the SVG shape (a 24×12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use the URL-encoder for SVG.
  • position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
  • width: 100% ensures the element stretches the entire width of its parent.
  • height: 12px is the same height as the shape.
  • bottom: 0 positions the pseudo element at the bottom of the parent.

继续阅读 30秒学会 CSS 片段 – Shape separator