Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (70 sloc) 2.28 KB
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
html, body {
font-size: 100%;
.wrapper {
__width: 960px;
position: relative;
*height: 1px;
.box {
position: relative;
background-color: yellow;
width: 160px;
height: 30px;
border: 2px solid red;
padding: 8px;
margin-bottom: 10px;
zoom: 1;
<div class="wrapper">
<div id="test">
<strong id="strong">hello</strong>
<em id="em">hello</em>
<!-- Grab Google CDN's jQuery, with a protocol relative URL -->
<script src=""></script>
<!-- Unit.js -->
<script src="Length.min.js"></script>
<!-- test -->
var units = ['10%', '96px', '25.4mm', '2.54cm', '1in', '72pt', '6pc', '25.4mozmm', '6rem', '10vh', '10vw', '10vm', '10vmin', '10vmax', '6em', '13.4ex', '12ch'],
i = units.length,
tmpl = '<div class="box" style="margin-left: {{css}}">{{label}}: {{value}}</div>',
vars = ['{{css}}', '{{label}}', '{{value}}'],
$el, $wrapper = $('.wrapper');
while (i--) {
$el = $(template(tmpl, vars, [units[i], 'Margin Left', units[i]])).appendTo($wrapper);
len = Length.toPx($el[0], units[i], 'marginLeft');
$(template(tmpl, vars, [len + 'px', 'Converted', units[i]])).appendTo($wrapper);
console.log(units[i], '=>', len + 'px');
// super simple tempate
function template(subject, substr, newSubStr) {
var i = substr.length, str = subject;
while (i--) {
str = str.replace(substr[i], newSubStr[i]);
return str;