试图确定如何在列中显示以下随机生成的列表?下面的代码生成一个垂直显示的引号。
目标是能够以 4 行的形式显示引号,而不仅仅是垂直显示。我该怎么做?
当前的 JS:
var my_res = _.sample([
'Quote 1',
'Quote 2',
'Quote 3',
'Quote 4',
'Quote 5',
'Quote 6'
], 5);
var arr_len = my_res.length;
var targ = document.getElementById('i_need_quotes_within_this');
for(i=0; i<arr_len; i++){
targ.innerHTML += "<q class=\"style\">"+my_res[i]+"</q><br/>"
}
当前的 CSS:
.style{
color: rgb 0, 0, 255;
background-color: firebrick;
font-size: 12px;
display: block;
border: 1px solid green ;
width: 300px;
height: 100px;
}
最佳答案
而不是将样式类应用于每个引用。将其应用于包含所有这些的 div。
CSS:
.style{
color: rgb 0, 0, 255;
background-color: firebrick;
font-size: 12px;
display: block;
border: 1px solid green ;
width: auto;
//height: 100px;
-webkit-column-count: 5; /* Chrome, Safari, Opera */
-moz-column-count: 5; /* Firefox */
column-count: 5;
-webkit-column-gap: 40px; /* Chrome, Safari, Opera */
-moz-column-gap: 40px; /* Firefox */
column-gap: 40px;
-webkit-column-rule: 4px outset green; /* Chrome, Safari, Opera */
-moz-column-rule: 4px outset green; /* Firefox */
column-rule: 4px outset green;
}
HTML:
<div id="i_need_quotes_within_this" class="style">
quote1<br/>
quote2<br/>
quote3<br/>
quote4<br/>
quote5<br/>
quote6<br/>
quote7<br/>
quote8<br/>
quote9<br/>
quote10<br/>
</div>
关于javascript - 如何使用 CSS 在列中显示随机生成的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730496/