簡體   English   中英

如何將100%的高度與最小的高度混合

[英]How to mix 100% height with a minimum height

我的問題很簡單,盡管解決方案似乎並不特別明顯。

我有一個Flash網站。 當前,Flash對象占據整個瀏覽器,並設置為width/height = 100% 除非有人縮小瀏覽器,否則這很好。

有沒有辦法設置像這樣的東西。

height = (browser_height < y) ? y : 100%;
width = (browser_width < x) ? x : 100%;

x和y是網站需要正確顯示的最小尺寸。

是否有CSS方式可以做到這一點? 如果不能,有些人不能告訴我如何在所有瀏覽器中跟蹤瀏覽器的可視區域?

只要知道xy ,就可以通過在包含Flash對象的元素上設置min-heightmin-width來實現:

<body>
    <div id="flastObj">
        flash object code here
    </div>
</body>

和CSS:

/* 100% height only works if the element's direct parent (body in 
   this example) also has a height specified */
html, body, #flashObj {
    height: 100%;
}

#flashObj {
    min-height: 900px; /* y value */
    min-width: 900px;  /* x value */
}

至於跟蹤可見區域的跨瀏覽器,我建議使用jQuery之類的Javascript庫。 它使捕獲窗口調整大小事件然后對其執行操作非常容易:

// constant width
var x = 900;

// Bind a handler to the window's load and resize events
$(window).bind('load resize', function(){
    // $(this) is a jQuery object that represent the element (our window) 
    // that we've got the event handlers bound to.
    var newWidth = $(this).width();
    var newHeight = $(this).height();

    // Now we can act on our #flashObj element
    var flashObj = $('#flashObj');
    if(newWidth < x){
        flashObj.css({width: x});
    } 
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM