cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="example">
    <p class="withClientRectsOverlay" style="width: 100px; height: 100px;">
        this is p
        <span>this is span this is span this is span this is span </span>
    </p>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span this is a span this is a span this is a span this is a span </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span>this is a span</span>
       this is a span this is a span this is a span 
   </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span style="display: inline-block; margin: 10px; height: 50px; line-height: 50px;">this 
            <span>is</span>
        a span</span>
       this is a span this is a span this is a span 
   </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span style="display: inline-block; margin: 10px; height: 50px; line-height: 50px;">this 
            <span style="margin: 10px;">is</span>
        a span</span>
       this is a span this is a span this is a span 
   </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span style="display: inline-block; margin: 10px; height: 50px; line-height: 50px;">this 
            <span style="display: inline-block;">is</span>
        a span</span>
       this is a span this is a span this is a span 
   </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span style="display: block; margin: 10px; height: 50px; line-height: 50px;">this <span>is</span> a span</span>
       this is a span this is a span this is a span 
   </span>
</div>

<div class="example">
   <span class="withClientRectsOverlay">this is a span 
       <span style="display: block; margin: 10px; height: 50px; line-height: 50px;">this <span style="margin: 10px">is</span> a span</span>
       this is a span this is a span this is a span 
   </span>
</div>
            
          
!
            
              .example {
    display: inline-block;
    vertical-align: top;
    width: 150px;
}
            
          
!
            
              function getRowRects(element) {
    var rects = [],
        clientRects = element.getClientRects(),
        len = clientRects.length,
        clientRect, top, rectsLen, rect, i;

    for(i=0; i<len; i++) {
        has = false;
        rectsLen = rects.length;
        clientRect = clientRects[i];
        top = clientRect.top;
        while(rectsLen--) {
            rect = rects[rectsLen];
            if (rect.top == top) {
                has = true;
                break;
            }
        }
        if(has) {
            rect.right = rect.right > clientRect.right ? rect.right : clientRect.right;
            rect.width = rect.right - rect.left;
        }
        else {
            rects.push({
                top: clientRect.top,
                right: clientRect.right,
                bottom: clientRect.bottom,
                left: clientRect.left,
                width: clientRect.width,
                height: clientRect.height
            });
        }
    }
    return rects;
}
function addRowRectsOverlay(elt) {
    // 为了使边框宽度与矩形宽度一致,这里给每个客户矩形上方绝对定位一个 div。
    // 注意:如果用户改变大小或者缩放,绘图将会重绘。

    var rects = getRowRects(elt);
    for (var i = 0; i != rects.length; i++) {
        var rect = rects[i];
        var tableRectDiv = document.createElement('div');
        tableRectDiv.style.boxSizing = 'border-box';
        tableRectDiv.style.position = 'absolute';
        tableRectDiv.style.border = '1px solid red';
        tableRectDiv.style.backgroundColor = 'rgba(255,0,0,.25)';
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
        tableRectDiv.style.margin = tableRectDiv.style.padding = '0';
        tableRectDiv.style.top = (rect.top + scrollTop) + 'px';
        tableRectDiv.style.left = (rect.left + scrollLeft) + 'px';
        tableRectDiv.style.width = rect.width + 'px';
        tableRectDiv.style.height = rect.height + 'px';
        document.body.appendChild(tableRectDiv);
    }
}

(function() {
  /* 给所有具有"widthClientRectsOverlay"样式的元素调用函数addRowRectsOverlay(elt) */
  var elt = document.getElementsByClassName('withClientRectsOverlay');
  for (var i = 0; i < elt.length; i++) {
    addRowRectsOverlay(elt[i]);
  }
})();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console