If I have a div
that expands to its contents, how can I ensure that its height is always a multiple of a given value, say, 50 pixels? Is there any way to do this with CSS, or would I need to resort to JavaScript?
views:
11answers:
2
+2
A:
Since CSS is not aware of the actual computed element dimensions, it cannot achieve what you ask. JavaScript can do this easily.
mingos
2010-09-09 15:20:28
+1
A:
You'll need JavaScript. In case the content doesn't change inline (with ajax or jquery or anything) you can use an onload event to start a script that checks the height and fixes it:
<body onload="javascript:fixHeight()">
<div id="thediv">
content
</div>
</body>
script:
function fixHeight() {
var thediv = document.getElementById('thediv');
thediv.style.height = ceil(thediv.offsetHeight / 50) * 50 + 'px';
}
(not tested)
Litso
2010-09-09 15:30:29