cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              .container
  %h1.retxt="Responsive to<br/> the <br/> Screen"

            
          
!
            
              body{background:#222;margin:0; padding:0; color:#DDD}
.container{width:100%; text-align:center;float:left}
.container2{width:50%;float:left;}
h1{text-transform:uppercase;margin:0; padding:0} 
            
          
!
            
              // Textsive
(function($){
  //Text + Responsive. Its not that clever huh?
  $.fn.textsive = function(options){
    //Accept Options
    var settings = $.extend({
      minFontSize:10,
      maxFontSize:1000,
      lineHeight:0.95,
      scale:1.25
    },options);
    
    //Return all instances
    return this.each(function(){
      var $this = $(this);
      //Regex finding all the <BR> <br> <br/> \r \n to determine line-breaks
      var newLines = $this.html().trim().split(/[\r\n]|<br\s*[\/]?>/gi);
      var nLines = [];
      //Clear out the original bit of text. I might need to make a less destructive method
      $this.text("");
      
      //Now that the text has been broken into its lines we need to wrap it in a block object to later detect the width. 
      for(var i = 0; i < newLines.length; i++){
        nLines[i] = ("<div>"+newLines[i]+"</div>");        
      }
      //Throw it back in now that "new lines" have been broken into full blocks
      $this.append(nLines);
      
      //So heres the function that gets called whenever the window is resized.
      //Already setup the "line-breaks" so we don't have to reconstruct those
      var resizeMe = function(){        
        /*So the thought here is to take the width of the container divided
        by the number of characters. Instead of the text being uniformly the
        the same size  I can get that nice scale variance where the characters
        form a block. Clamping function for some control, but I like it without.
        */
        
        $this.find("div").each(function(i){
          var c = ($(this).width() / $(this).text().trim().length)*settings.scale ;
          
          $(this).css({
              fontSize:  Math.min(Math.max(c, settings.minFontSize), settings.maxFontSize),
              lineHeight: settings.lineHeight +"em"
              
          });
        });
      };
      
      resizeMe();
      $(window).on("resize",resizeMe);
    });
  };  
}(jQuery));

$("h1").textsive({lineHeight:0.85, scale:1.1}); 

            
          
!
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