CSS3-用不同大小的可变数量的矩形填充网页的最短方法
CSS3 - shortest way fill a webpage with a variable number of rectangles of different sizes
我想制作一个html5模板,其中页面用矩形填充。
如果只有一个矩形,它将占据整个屏幕。然后,其他矩形将从底部升起,吃掉第一个矩形的位置。每个矩形都必须是一个html元素,因为我会在上面加上背景大小:封面(所以使用剩余的容器空间来组成第一个矩形不是一个可行的解决方案)。有两种布局,一种有两列,另一种有三列。
可以获得确切的行为 此处:JS BIN
它运行得很好,但我认为有更短更好的方法可以做到这一点。
周围有CSS专家吗?JS解决方案也可以,但前提是它更短。LESScss也可以使用。
也许是列数?
Masony是一个有趣的框架,可以帮助您处理您的情况。。。或者可能将你的想法提升到一个新的水平。
看看这个网站,看看它是否能帮助你的努力:http://masonry.desandro.com/
这样?
这只解决你的"肖像"部分
HTML
<div class="container"></div>
CSS
.container {
width:100%;
}
.box {
background-color:red;
display:inline-block;
height: 25%;
width: 50%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
border:1px solid blue;
text-align:center;
}
.fullWidth {
width:100%;
}
JS
$(document).ready(function () {
var maxNum = 12;
var startNum = 1;
function render() {
if (startNum % 2 === 0) {
$(".container").children(".box:nth-of-type(odd)").removeClass("fullWidth");
$(".container").append("<div class='box'>" + startNum + "</div>");
} else {
$(".container").append("<div class='box fullWidth'>" + startNum + " </div>");
}
if (startNum < maxNum) {
setTimeout(render, 1500);
}
startNum++;
}
render();
});
编辑添加了"横向"部分
像这样?
这只解决您的"横向"部分
HTML
<div class="container"></div>
CSS
.container {
width:100%;
}
.box {
background-color:red;
display:inline-block;
height: 25%;
width: 33.333%;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
border:1px solid blue;
text-align:center;
}
.halfWidth {
width:50%;
}
.fullWidth {
width:100%;
}
JS
$(document).ready(function () {
var maxNum = 12;
var startNum = 1;
function render() {
if (startNum % 3 === 0) {
$(".container").children(".box").removeClass("halfWidth");
$(".container").append("<div class='box'>" + startNum + "</div>");
} else if ((startNum - 2) % 3 === 0) {
$(".container").children(".box:nth-of-type(" + (startNum - 1) + ")").removeClass("fullWidth").addClass("halfWidth");
$(".container").append("<div class='box halfWidth'>" + startNum + "</div>");
} else {
$(".container").append("<div class='box fullWidth'>" + startNum + " </div>");
}
if (startNum < maxNum) {
setTimeout(render, 1500);
}
startNum++;
}
render();
});
相关文章:
- 如何设置html元素填充的动画
- 如何使用jquery在填充自动完成的值后使文本框只读
- 如何通过ajax刷新JSF填充的javascript变量
- 如何让iframe在设置负上边距后填充整个移动网页
- 从网页预填充网页
- 用Instagram提要填充网页并调整大小
- 有没有办法让我用另一个网站的图片自动填充我的网页
- 使用 PHP/JS 使用上传的文件动态填充网页
- 用于在网页上填充图像链接的 JavaScript 代码
- 我如何用图片填充我的网页
- 使用 AJAX 从两页上的数据填充网页
- CSS3-用不同大小的可变数量的矩形填充网页的最短方法
- 从网页获取内容,这是通过javascript填充
- 使用Javascript自动填充网页用户名密码
- 通过URL预填充网页字段
- 如何使用jquery获取数据并动态填充网页
- Dojo:在网页中填充本地json文件的树状结构
- 自动填充文本框和模拟按钮点击网页
- 如何停止在html网页中动态更改正文的填充
- 从Google电子表格数据在网页上构建/填充下拉菜单