Skip to content

Instantly share code, notes, and snippets.

@PrideChung
Created May 9, 2012 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrideChung/2643180 to your computer and use it in GitHub Desktop.
Save PrideChung/2643180 to your computer and use it in GitHub Desktop.
css: limit HTML element's max width/height (compatible with IE6)
<style> selector{ max-width:100px; } </style>
<!--[if IE 6]>
<style>
selector{ _width:expression(this.width>100?(function(dom){dom.style.width='100px';})(this):'auto');} </style>
<![endif]-->
<!-- NOTICE: target element must NOT set width or height attribute, or this doesn't work -->
<!-- I made a Sublime Text snippet, maybe can also use in TextMate -->
<snippet>
<content><![CDATA[
<style> ${1:selector}{ max-width:${2:maxwidth}px; } </style>
<!--[if IE 6]>
<style> ${1}{ _width:expression(this.width>${2}?(function(dom){dom.style.width='${2}px';})(this):'auto'); } </style>
<![endif]-->
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>maxwidth</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment