【发布时间】:2018-10-11 10:07:38
【问题描述】:
所以,
我已经为一个网站创建了一个四列流体宽度布局,并且我正在努力在我的一个列中放置一个流体方形 DIV。我发现有一些技术可以实现这一点 - 即,将 padding-bottom 设置为与宽度相同的百分比 - 但当 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“标志”是我试图保持为正方形的标志。现在,我使用了 padding-bottom 方法,但是当 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。
【问题讨论】:
标签: html css fluid-layout