collapsedMarginTop property

double get collapsedMarginTop

Implementation

double get collapsedMarginTop {
  double marginTop;

  if (effectiveDisplay == CSSDisplay.inline) {
    marginTop = 0;
    return marginTop;
  }

  // Margin collapse does not work on following case:
  // 1. Document root element(HTML)
  // 2. Inline level elements
  // 3. Inner renderBox of element with overflow auto/scroll
  if (isDocumentRootBox() || (effectiveDisplay != CSSDisplay.block && effectiveDisplay != CSSDisplay.flex)) {
    marginTop = this.marginTop.computedValue;
    return marginTop;
  }

  // If there is any previous attached render sibling (including placeholders
  // for positioned elements), do not treat this element as the first in-flow
  // child for parent-top collapsing. This matches the engine’s placeholder
  // approach used to anchor static position of positioned siblings, and
  // preserves expected spacing when a positioned sibling precedes.
  final bool hasPrevInFlow = isPreviousSiblingAreRenderObject();
  if (!hasPrevInFlow) {
    // First in-flow child: may collapse with parent top
    marginTop = _collapsedMarginTopWithParent;
  } else {
    // Subsequent in-flow child: do not collapse with previous sibling here.
    // Parent layout combines prev bottom and this top per spec.
    marginTop = _collapsedMarginTopWithFirstChild;
  }

  return marginTop;
}