English 中文(简体)
1. 扩大四级高
原标题:Expand div height with interval

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");
});

这似乎就是做的!

问题回答

现有解决办法的问题在于,这些解决办法没有考虑到,你会重新在四分五裂时形成固定的高度,而不管内容是什么。 因此,你需要一个要素告诉你,内容高度是,然后总结要素具有背景,并根据内层内容的高度变化加以扩大。

This jsFiddle example should speak for itself, the interval is ofcourse for testing / demo as is the css. http://jsfiddle.net/sg3s/uHsVg/

The example JS:

setInterval(function() {
    var $inner = $( #innerContent ),
        $outer = $( #outerDiv );

    // Change the contents.... 
    $inner.text($inner.text() +   lorem ipsum dolor sit amet );

    // Height changed over treshhold? treshhold = outerheight
    if ($outer.height() <= $inner.height()) {
        $outer.height(Math.ceil($inner.height() / 10) * 10);
    }

}, 250);

例:

<div id="outerDiv">
    <div id="innerContent">Test</div>
</div>

这种扩大的四舍五入并不一定是绝对的,或是任何东西,它像任何常规的html阻塞部分一样,固定的高度。

<>strong>Edit:如果发言,也使它缩小,仅仅消除了僵局,我只是说,只有这样,它才能真正改变,而不仅仅是any。 改变

介绍本中心:

background-size: cover;

如果该元素已穿过或边界(如果已经,你需要对这些要素进行说明),并且已经进行过检测,那么这项工作就没有了。

jQuery( document ).ready(
    function(){
    var div = jQuery("#pattern-div"), curHeight = div.height();

    div.css( "height", Math.ceil( curHeight / 10 ) * 10 );

        window.setInterval(
            function(){

            var newHeight = div.height(), roundedHeight;

                if( newHeight !== curHeight ) {
                roundedHeight = Math.ceil( newHeight / 10 ) * 10;
                curHeight = roundedHeight;
                div.css( "height", roundedHeight );
                }

            },
        200 );
    }
);

It keeps checking if the automatic height has changed, ceils it up to nearest 10 and sets it as the height.

Ahh, I see, so you always want your div size to be a multiple of 10.

当内容得到更新时,你应发射或称呼一项功能,然后将四级高射到下一个最大多级,例如:

function DivSize(el) { 
    $(el).css( height ,$(el).height()+(10-$(el).height()%10)+ px );
}

你的四位将担任以下职务:绝对;或:相对;高度至工作。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签