Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="Card">
  <div class="Card-FullNameLabel">ÀÇĤjgpfhjklbĜiEstosTreMalfaciÀÇĤjgpfhjklbĜiEstosTreMalfaci</div>
  <div class="Card-OrganizationNameLabel">ÀÇĤjgpfhjklbĜiEstosTreMalfaciÀÇĤjgpfhjklbĜiEstosTreMalfaci</div>
</div>

<!-- ▼ #DELETE-ME: Demonstration Markup ▼ -->
<div class="Card DeleteMe">
  <div class="Card-FullNameLabel--DeleteMe">ÀÇĤjgpfhjklbĜiEstosTreMalfaciÀÇĤjgpfhjklbĜiEstosTreMalfaci</div>
  <div class="Card-OrganizationNameLabel--DeleteMe">ÀÇĤjgpfhjklbĜiEstosTreMalfaciÀÇĤjgpfhjklbĜiEstosTreMalfaci</div>
</div>

              
            
!

CSS

              
                // Required for use of `math` rounding methods
@use 'sass:math';

// Text truncation CSS
@mixin TextTruncation($displayEllipsis: false) {
  overflow: hidden;
  white-space: nowrap;
  
  @if ($displayEllipsis) {
    text-overflow: ellipsis;
  } @else {
    text-overflow: clip;
  }
}

// Formula for calculating negative margin offset
@function CalculateMargin($thisFontSize, $thisLineHeight) {
  @return math.floor(math.floor($thisFontSize * $thisLineHeight) - $thisFontSize) / 2;
}

// Minimum `line-height` needed to show all ascenders & descenders
$minLineHeight: 1.5;

// Function to calculate `margin` offsets to compensate for adjusted `line-height`
@function GetOffset($thisFontSize, $thisLineHeight) {
  @if ($thisLineHeight < $minLineHeight) {    
    $offsetByMinLineHeight: CalculateMargin($thisFontSize, $minLineHeight);

    @if ($thisLineHeight == 1) {
      @return $offsetByMinLineHeight;
    } @else {
      @return $offsetByMinLineHeight - CalculateMargin($thisFontSize, $thisLineHeight);
    }  
  } @else {
    @return 0;
  }  
}

// Set `font-size`, `line-height`, and calculated `margin` offsets
@mixin BuildLabel($thisFontSize, $thisLineHeight) {
  @include TextTruncation(true);
  font-size: $thisFontSize;
  
  @if ($thisLineHeight < $minLineHeight) {
    $offset: math.floor(GetOffset($thisFontSize, $thisLineHeight));
    line-height: $minLineHeight;
    margin: -$offset 0;
  } @else {
    line-height: $thisLineHeight;
  }
}

// Wrapper for BuildLabel that includes `margin-top` of next sibling
@mixin BuildLabelWithGap(
  $thisFontSize,
  $thisLineHeight,
  $siblingFontSize,
  $siblingLineHeight,
  $siblingMarginTop: 0
) {
  $siblingOffset: GetOffset($siblingFontSize, $siblingLineHeight);
  @include BuildLabel($thisFontSize, $thisLineHeight);

  @if ($siblingMarginTop > 0) {
    &.Card-FullNameLabel + .Card-OrganizationNameLabel {
      margin-top: math.floor($siblingMarginTop) - $siblingOffset;
    }
  }
}

// Global default `line-height`
$globalLineHeight: 1;

body {
  padding: 12px;
}

* {
  line-height: $globalLineHeight;
  font-family: Arial, sans-serif;
}

.Card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 240px;
  height: 320px;
  padding: 6px 12px 12px;
  background: white;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
  
  & > * {
    // Required when the flex parent has `align-items: center`
    max-width: 100%;
  }
}

// `.Card-FullNameLabel` values
$fullNameFontSize: 16px;
$fullNameLineHeight: $globalLineHeight; // (1)

// `.Card-OrganizationNameLabel` values
$orgNameFontSize: 12px;
$orgNameLineHeight: $globalLineHeight; // (1)
$orgNameMarginTop: 6px;

.Card-FullNameLabel {
  @include BuildLabelWithGap(
    $fullNameFontSize,
    $fullNameLineHeight,
    $orgNameFontSize,
    $orgNameLineHeight,
    $orgNameMarginTop
  );
  color: #707070;
}

.Card-OrganizationNameLabel {
  @include BuildLabel($orgNameFontSize, $orgNameLineHeight);
  color: #A2A2A2;
}


/********************************************************************************
  ▼ #DELETE-ME: Delte everything below this line. CSS for demonstration only. ▼
********************************************************************************/

    .Card {
      position: relative;

      &::before,
      &::after {
        display: block;
        position: absolute;
        color: silver;
      }

      &::before {
        left: calc(100% + 24px);
        width: 100%;
        font-size: 16px;
        top: 12px;
        content: "◄ hover Card to toggle state";
      }
      
      &::after {
        font-size: 20px;
        right: 12px;
        bottom: 12px;
        content: "(with fix)";
      }
    }

    .Card.DeleteMe {
      position: absolute;
      top: 12px;
      left: 12px;
      background: #fff;
      opacity: 0;
      box-shadow: none;

      &:hover {
        opacity: 1;
      }

      &::before {
        display: none;
      }

      &::after {
        content: "(original)";
      }
    }

    // No offsets, just setting `font-size` and `line-height` values directly
    // to simulate "Original" state with bug in question
    .Card-FullNameLabel--DeleteMe {
      @include TextTruncation(true);
      font-size: $fullNameFontSize;
      line-height: $fullNameLineHeight;
      color: #707070;
    }

    // No offsets, just setting `font-size` and `line-height` values directly
    // to simulate "Original" state with bug in question
    .Card-OrganizationNameLabel--DeleteMe {
      @include TextTruncation(true);
      font-size: $orgNameFontSize;
      line-height: $orgNameLineHeight;
      color: #A2A2A2;
    }

    // No offset, just setting `margin-top` value directly
    // to simulate "Original" state with bug in question
    .Card-FullNameLabel--DeleteMe + .Card-OrganizationNameLabel--DeleteMe {
      margin-top: $orgNameMarginTop;  
    }

              
            
!

JS

              
                
              
            
!
999px

Console