我創建了一個網站四柱液體寬度的佈局,和我的工作將流體正方形的DIV,我的一列中。我發現有幾種技術可以實現這一點 - 即將填充底部設置爲與寬度相同的百分比 - 但是當DIV包含內容時,這些技巧似乎都不起作用。
當DIV包含內容時,是否有辦法在流體DIV上保持1:1(方形)比率?
這裏是我的HTML:
<div id="leftmostcolumn">
<div id="logo"></div>
</div>
<div id="leftcolumn"></div>
<div id="rightcolumn"></div>
<div id="rightmostcolumn"></div>
我的CSS:
body {
width: 100%;
height: 100%;
background-color: red;
}
#leftmostcolumn {
position: absolute;
top: 0;
left: 0;
width: 25%;
height: 100%;
background-color: blue;
}
#leftcolumn {
position: absolute;
top: 0;
left: 25%;
width: 25%;
height: 100%;
background-color: green;
}
#rightcolumn {
position: absolute;
top: 0;
left: 50%;
width: 25%;
height: 100%;
background-color: yellow;
}
#rightmostcolumn {
position: absolute;
top: 0;
left: 75%;
width: 25%;
height: 100%;
background-color: gray;
}
#logo {
width:100%;
padding-bottom:100%;
background-color: #aa2d2d;
color: white;
}
這裏還有一個JsFiddle。
DIV「徽標」是我試圖維護的一個正方形。現在,我已經使用了填充底部方法,但是當DIV中有內容時,這並不起作用。任何輸入非常感謝!
馬卡報
編輯:
到達那裏......我改編劇本,我發現找到DIV的寬度,然後該值適用於高度,以保持它的方。然而,現在的腳本並沒有不斷調整DIV的大小,並且它不會讓它縮小到一定的尺寸以下。有關如何糾正這些問題的任何想法?
HTML:
<div id="box"></div>
CSS: #box { width: 75%; height: 50px; background-color: black; }
JQUERY:
$("#box").css("height", function() {
return $(this).width();
});
的jsfiddle是here。