I m working with a div that has a pattern-image as background. The pattern is repeatable but is preferred to expand with an interval of pixels.
我愿知道,是否有办法扩大四舍五入,但随着案文的补足,这一办法仍在扩大。
Say the pattern is best viewed with the interval of 10px, eg. height:120px, 130px, 140px etc. A div is present with dynamic content and as the height of the div expands the height is fixed to the next possible height within the interval. Eg. the original height of the div is 132px, which should be transformed into 140px automatically.
Is this possible? I ve added the jquery tag since I assume this is not possible with CSS alone and javascript/jquery is my guess for a solution :)
我合并了两个现有答案的解决办法:
$(function(){
var DivSize = function(el) {
$(el).css( height ,Math.ceil( $(el).height() / 10 ) * 10+ px );
}
DivSize("#test");
});
这似乎就是做的!