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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 id="app"></div>

<script type="text/jsx">
	var data = { 
	"sections": [{
	      "label": "Absolute Length Units", 
	      "items": [
	      	{"unitName":"px", "unitDescription":"Relative to the viewing device. For screen display, typically one device pixel (dot) of the display. For printers and very high resolution screens one CSS pixel implies multiple device pixels, so that the number of pixel per inch stays around 96."}, 
	      	{"unitName":"pt", "unitDescription":"One point (which is 1/72 of an inch)."},
	      	{"unitName":"mm", "unitDescription":"One millimeter."},
	      	{"unitName":"pc", "unitDescription":"One pica (which is 12 points)."}, 
	      	{"unitName":"cm", "unitDescription":"One centimeter (10 millimeters)."}, 
	      	{"unitName":"in", "unitDescription":"One inch (2.54 centimeters)."}]
	    }, 
	    {
	      "label": "Relative Units (Relative to width of positioned parent)", 
	      "items": [{"unitName":"percent","unitDescription":"MDN states that: although percentage values are also CSS dimensions and are accepted by some CSS properties that accept <length> values, they are not themselves, <length> values. However, since it is widely used, I've included it here."}]
	    }, 
	    {
	      "label": "Viewport Relative units", 
	      "items": [
	      	{"unitName":"vw",  "unitDescription":"1/100th of the width of the viewport."},
	      	{"unitName":"vh",  "unitDescription":"1/100th of the height of the viewport."},
	      	{"unitName":"vmin","unitDescription":"1/100th of the minimum value between the height and the width of the viewport."},
	      	{"unitName":"vmax","unitDescription":"1/100th of the maximum value between the height and the width of the viewport."}]
	    }, 
	    {
	    "label": "Font Relative Units", 
	    "items": [
	    	{"unitName":"ex","unitDescription":"This unit represents the x-height of the element's font. On fonts with the 'x' letter, this is generally the height of lowercase letters in the font; 1ex ≈ 0.5em in many fonts."},
	    	{"unitName":"ch","unitDescription":"This unit represents the width, or more precisely the advance measure, of the glyph '0' (zero, the Unicode character U+0030) in the element's font."}, 
	    	{"unitName":"em","unitDescription":"This unit represents the calculated font-size of the element. If used on the font-size property itself, it represents the inherited font-size of the element."},
	    	{"unitName":"rem","unitDescription":"This unit represents the font-size of the root element (e.g. the font-size of the <html> element). When used on the font-size on this root element, it represents its initial value."}]
	  	}]
	}

	var availableFonts = ["Times New Roman", "Arial", "Avenir", "Courier","Georgia", "Fantasy", "Helvetica Neue","Helvetica","Impact", "Lucida Grande","Monospace", "Myriad","RockWell","Tahoma","Times","Trebuchet MS","Verdana"]
	var availableFontSizes = ["8px","10px","12px","14px","16px","18px","21px","24px","26px"]

	var App = React.createClass({
		getInitialState: function(){
			return {data:data, activeUnit:""}; 
		},
		handleUnitMouseEnter: function(unit){
			this.setState({activeUnit: unit.unitName})
		}, 
		handleUnitMouseLeave: function(){
			this.setState({activeUnit:""})
		}, 
		render: function(){
			var activeUnit = this.state.activeUnit; 
			var handleMouseEnter = this.handleUnitMouseEnter; 
			var handleMouseLeave = this.handleUnitMouseLeave;
			var sections = this.state.data.sections.map(function(section){
				return <Section label={section.label} units ={section.items} activeUnit={activeUnit} handleMouseEnter = {handleMouseEnter} handleMouseLeave ={handleMouseLeave} /> 
			})
			return (
				<div className="css-ruler"> 
					<h1>CSS ruler</h1>
					{sections}
				</div>  
			); 
		}
	})

	var Section = React.createClass({
		getInitialState: function(){
			return {fontFamily:"", fontSize:'16px'}; 
		}, 
		onFontChange: function(font){
			this.setState({fontFamily:font})
		}, 
		onFontSizeChange: function(size){
			this.setState({fontSize:size})
		},
		render: function(){
			var activeUnit = this.props.activeUnit; 
			var handleMouseEnter = this.props.handleMouseEnter; 
			var handleMouseLeave = this.props.handleMouseLeave; 
			
			var units = this.props.units.map(function(unit){
				var isActive = (unit.unitName == activeUnit)? 'active':'inactive';
			
				if (activeUnit == ""){
					isActive = ""
				} 
				return <Unit unit={unit} isActive={isActive} handleMouseEnter={handleMouseEnter} handleMouseLeave={handleMouseLeave} />  
			})

			var fontForm = {}; 
			if (this.props.label.match('Font')){
				fontForm = <FontForm onFontChange={this.onFontChange} onFontSizeChange={this.onFontSizeChange}/>
			}

			return (
				<div style={{fontFamily:this.state.fontFamily, fontSize:this.state.fontSize}}>
					<div className="section-label">
					{this.props.label}
					</div>
					{fontForm }
					{units}
				</div> 
			); 
		}
	})
	
	var Unit = React.createClass({
		onMouseEnter: function(item){
			this.props.handleMouseEnter(item);
		}, 
		onMouseLeave: function(item){
			this.props.handleMouseLeave(item);
		}, 
		render: function(){
			var cx = React.addons.classSet;
			var isActive = this.props.isActive
			var unitClasses = cx('unit', this.props.unit.unitName, isActive);
			var unitStyles = {backgroundSize: "1"+this.props.unit.unitName+" 100%"}
			var style = {'position':'relative'}
			var descriptionStyle = cx('unit-description', isActive);
			return (
				<div style={style}> 
					<div className="unit-label">{this.props.unit.unitName}</div>
					<div className={unitClasses} onMouseEnter={this.onMouseEnter.bind(this, this.props.unit)} onMouseLeave={this.onMouseLeave.bind(this, this.props.unit.unitName)}  style={unitStyles}></div> 
					<div className={descriptionStyle}>{this.props.unit.unitDescription}</div> 
				</div> 
			)
		}
	})

	var FontForm = React.createClass({
		
		handleFontChange: function(event){

			this.props.onFontChange(event.target.value); 
		},
		handleFontSizeChange: function(event){
			this.props.onFontSizeChange(event.target.value); 
		}, 
		handleBaseSizeChange: function(event){
			$('html').css('font-size',event.target.value); 
		},
		render: function(){
			var fontOptions = availableFonts.map(function(font){
				return <option value={font}>{font}</option>
			})

			var sizeOptions = availableFontSizes.map(function(size){
				return <option value={size} selected={size == "16px"}>{size}</option>
			})
			return(
			<div> 
				<label>font:</label>
				<select onChange={this.handleFontChange}>
					{fontOptions}
				</select>

				<label>font size:</label>
				<select onChange={this.handleFontSizeChange}>
					{sizeOptions}
				</select>
				
				<label>Base font size:</label>
				<select onChange={this.handleBaseSizeChange}>
					{sizeOptions}
				</select>

			</div> 
			)
		}
	})
	React.render(
	  <App />,
	  document.getElementById('app')
	);
</script> 
  
            
          
!
            
              @unitHeight: 20px; 
@bodyBG:  #70A8B2; 
@rulerBG: #FAFAFA; 
@labelColor: #000; 
@unitColor: #000;
@unitLineColor:  #70A8B2;  
body{
	margin: 0; 
	background-color: @bodyBG; 
	padding: 20px; 
}
.css-ruler{
	display: block; 
	margin: 0 auto;
	padding: 20px 20px 40px 20px;
	position: relative; 
	max-width: 800px; 
	min-height: 200px;
	outline: 1px solid darken(@bodyBG, 5%);
	padding-left: 100px;
	background-color: @rulerBG; 
	box-shadow: 0px 7px 22px rgba(0, 0, 0, 0.1); 
	margin-top: 30px;
}

.section-label{
	width: 100%;
	display: block; 
	text-align: left;
	padding-bottom: 10px;
	margin-left: -90px;
	padding-top: 20px;
	font-family: 'Avenir', 'Helvetica Neue', Helvetica, Arial, sans-serif;
	color: @labelColor; 
	font-size: 16px;
}

.unit-label {
	position: absolute;
	width: 100px;
	text-align: right;
	left: -5px;
	text-transform: uppercase; 
	font-size: 10px;
	line-height: @unitHeight; 
	font-family: 'Avenir', 'Helvetica Neue', Helvetica, Arial, sans-serif;
	color: @unitColor; 
	left: -110px;
}
label{
	font-weight: normal; 
}
em{
font-weight: bold; 
}

.unit, .px {
	height: @unitHeight;
	width: 100%;
	outline: 1px solid @bodyBG;
	background-image: linear-gradient(left, @unitLineColor 1px, transparent 0px);
	background-repeat: repeat;
	background-size: 2px 100%;
	transition: all 0.1s ease-in;
	position: relative; 
}	
.px, .pt{
	background-size: 2px 100% !important; 
}
.percent {
	background-size: 2% 100%; 
}
.unit.active{
	opacity: 1; 
}
.unit.inactive{
	opacity: 0.2; 
}

.unit-description{
	max-width: 380px;
	width: 80%;
	position: absolute;
	right: 0;
	display: block;
	top: 100%;
	background-color: @unitLineColor;
	z-index: 1;
	padding: 5px;
	color: #FFF;
	display: none; 
	font-family: 'Avenir', 'Helvetica Neue', Helvetica, Arial, sans-serif;
	font-size: 14px; 
	box-shadow: 0 16px 24px rgba(0,0,0,0.2); 
	transition: all 0.2s ease-in; 
	opacity: 0; 
}
.unit-description.active{
	display: block; 
	opacity: 1; 
}
label{
	opacity: 0.4; 
}

select{
	margin-right: 24px; 
	margin-left: 4px; 
	margin-bottom: 6px; 
	vertical-align: baseline; 
	font-size: inherit; 
}

h1{
	position: absolute;
	bottom: 99%;
	margin: 0;
	padding: 0;
	left: 0;
	color: @rulerBG;
	font-family: 'Avenir', 'Helvetica Neue', Helvetica, Arial, sans-serif;
	line-height: 30px;
	font-size: 36px; 

}


@media screen and (max-width:480px){
	.css-ruler{
		padding-left: 60px;
	}
	.section-label{
		margin-left: -50px;
		width: 100%;
	}
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console