0

I have a list being returned from a database that can potentially be a different size each time. The list is loaded onto a html page <div id="availableTimes"></div> using

$.each(returnData.availableTimes, function (index, value) {                        
     $("#availableTimes").append('<input type=radio name=availableTimes value= ' 
        + value.id + '>' + '<label id=' + value.id + '>' + value.time + '</label>');
});

What I would like to be able to do is limit the amount of radio buttons and labels displayed per line to 4. Is there a value I can set in CSS or do I have to insert a <br /> every 4 records in the JavaScript?

4

3 回答 3

4

You could use nth-child selectors to clear every 5th element (that has been floated). Really, you can break the line however you want, just use the nth-child selector to do so...

Like so:

#availableTimes input {
    float:left;
}

#availableTimes input:nth-child(4n + 1) {
    clear:left;
}

EDIT: use (4n + 1) rather than (5n)

于 2013-07-24T15:45:34.553 回答
1

没有浮动,您可以在标签上添加换行符

#availableTimes label:nth-child():after {
    content:"\a";
    white-space: pre;
}

演示:http: //jsfiddle.net/8FALp/1/

于 2013-07-24T16:08:33.680 回答
0

简短的回答是,您需要<br>每四条记录放置一个标签。AFAIK,没有办法只使用 CSS 创建换行符。如果您想研究一下,这个 SO question还有更多解决方案

于 2013-07-24T15:44:12.903 回答