Created
May 9, 2012 09:07
-
-
Save PrideChung/2643180 to your computer and use it in GitHub Desktop.
css: limit HTML element's max width/height (compatible with IE6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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