我想我的代码看起来像这样: wanted appearance
我不想使用css变量 - 这不是好主意。如何使所有html元素看起来不同?有可能在一个div中做到吗?
function createGrid(x, y) {
for (var cols = 0; cols < x; cols++) {
for (var rows = 0; rows < y; rows++) {
$('#container').append("<div class='grid'></div>");
};
};
$('.grid').width(800 / x);
$('.grid').height(800 / x);
};
function getData(count) {
var names = ["Michał", "Jan", "Katarzyna", "Andrzej", "Józef", "Bartek", "Mikołaj", "Tomasz", "Julian", "Brajan", "Dżesika"];
var surnames = ["Noga", "Kowalski", "Nowak", "Pazura", "Duda", "Komorowski", "Tomczyk", "Józefowicz", "Lechicki", "Goldberg"];
var result = [];
for (var i = 0; i < count; i++) {
var randomNameIndex = Math.floor(Math.random() * names.length);
var randomSurnameIndex = Math.floor(Math.random() * surnames.length);
var name = names[randomNameIndex];
var surname = surnames[randomSurnameIndex];
result.push({
name: name,
surname: surname
});
}
return result
}
#container {
position: relative;
margin:auto;
height:800px;
width:800px;
}
.grid{
outline:5px solid white;
margin:0;
padding:0;
border:none;
background-color: #212121;
display:inline-block;
}
<body>
<div id="container"></div>
</body>
</html>
答案 0 :(得分:0)
你将不可避免地最终使用css,我建议你这样做:
1.-你可以定义类(红色,白色,灰色,blut等),然后在你的createGrid
逻辑选择类中随机。
2.-或者可以使用随机背景颜色并注入您的元素。
但最后是css。是改变风格的唯一方法。