admin管理员组文章数量:1333685
I'm looking for a good way to do a vertical wrap. My goal is to fit a list of checkboxes into a div. I have the checkboxes sorted alphabetically, and I want the list to flow from the top of the div to the bottom and then begin again in a new column when they reach the bottom. Right now, I can do this by breaking the list into chunks of a predefined size on the server-side before feeding it into my html template. But things get messy when the list gets so long that you have to scroll. I'm hoping to force it to scroll horizontally only. This is not so easy, since I'm holding each chunk in a floating div, so white-space:nowrap doesn't seem to cut it. Currently, I'm using javascript count the number of list chunks and extend the width of an intermediary container (inside the div that serves as the viewport but containing the divs that contain the data). I want something that looks roughly like this:
__________________________
| []..... []..... []..... |
| []..... []..... []..... |
| []..... []..... |
| []..... []..... |
|__________________________|
|<|_____________|___||___|>|
So I guess I have two questions:
- Is there a good way to vertically wrap a list?
- Is there a good way to force horizontal scrolling when the data gets too large for the viewport?
I'm looking for a good way to do a vertical wrap. My goal is to fit a list of checkboxes into a div. I have the checkboxes sorted alphabetically, and I want the list to flow from the top of the div to the bottom and then begin again in a new column when they reach the bottom. Right now, I can do this by breaking the list into chunks of a predefined size on the server-side before feeding it into my html template. But things get messy when the list gets so long that you have to scroll. I'm hoping to force it to scroll horizontally only. This is not so easy, since I'm holding each chunk in a floating div, so white-space:nowrap doesn't seem to cut it. Currently, I'm using javascript count the number of list chunks and extend the width of an intermediary container (inside the div that serves as the viewport but containing the divs that contain the data). I want something that looks roughly like this:
__________________________
| []..... []..... []..... |
| []..... []..... []..... |
| []..... []..... |
| []..... []..... |
|__________________________|
|<|_____________|___||___|>|
So I guess I have two questions:
- Is there a good way to vertically wrap a list?
- Is there a good way to force horizontal scrolling when the data gets too large for the viewport?
- This isn't exactly what you want, but check out this: docs.jquery./UI/Accordion – Malfist Commented Jan 23, 2009 at 22:41
- @Malfist: Your right its not even close. – AnthonyWJones Commented Jan 23, 2009 at 23:03
5 Answers
Reset to default 4I'd use CSS3 columns. However, only WebKit (Safari, Chrome, ...) and Gecko (Firefox, ...) have implemented it so far, and you'll have to add their respective vendor prefixes (-moz-column-width:...; -webkit-column-width:...;
) for it to work.
If IE has to get columns, floated divs would probably be the best way.
I'll get downvoted to hell for saying this, but ... use a table!
Well it's not the prettiest way but it can solve your problem i guess
I use this chunk of Xsl to generate a table with a fixed number of rows:-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" />
<xsl:variable name="rowCount" select="6" />
<xsl:template match="/*">
<table rules="all">
<xsl:for-each select="item[position() <= $rowCount]">
<tr>
<xsl:for-each select=". | following-sibling::item[position() mod $rowCount = 0]">
<td><xsl:value-of select="." /></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
You can replace the rowCount variable with a parameter. All you then need is to calculate how many rows the vertical client height of the view port will take (bear in mind you loose some when the horizontal scroll bar appears, I would make it always visible).
This could be adapted to a set of floating divs but I wouldn't bother. Your viewport just needs to be a div with a fixed height/width and overflow-x:scroll; overflow-y:hidden.
To manage the scroll of your viewport, you can set the CSS overflow property:
div#viewport{
overflow: scroll;
overflow-x: scroll; /* not sure if it's standard */
height: 150px;
}
I ended up using a little server-side preprocessing. This site, and this particular page, ended up needing a fair amount of preprocessing anyway, and I don't expect the size of the data to get too huge.
本文标签: javascriptVertical Wrapping in HTMLStack Overflow
版权声明:本文标题:javascript - Vertical Wrapping in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742257559a2441906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论