主要思想是我有一个没有定义长度(动态)的字符串,我需要将它分组为多个列(如图像示例中所示,忽略图像部分)。
所以,你可以看到它必须精确。我的主要想法是将字符串简介分为单词数组,将每个单词附加到容器中,并检查文本容器是否适合父容器(已修复)。虽然这个想法可能会起作用,但它似乎有点矫枉过正,所以,有没有人对如何处理这个问题有更好的想法?我不能使用css属性,它必须严格地从js完成,因为我必须进一步将该文本与列中的图像分组。
为了清楚起见,我没有三列,这也是动态的,我可以有1到4列。
答案 0 :(得分:0)
反正
我没有得到我希望得到的答案,我按照我的方式实现了它,通过将文本分成一个单词数组并在追加每个单词后检查容器尺寸。它有效!
我仍然坚持这个问题,因为也许有人可能需要类似的东西。
答案 1 :(得分:-1)
你知道CSS3多列布局吗? 请参阅示例here。
答案 2 :(得分:-1)
呃...... column-count:3
?
<div style="column-count:3; -webkit-column-count:3; -moz-column-count: 3;">
<p>Bacon ipsum dolor amet capicola landjaeger ribeye beef ribs. Ham landjaeger prosciutto corned beef porchetta, pancetta tongue hamburger meatball picanha pig spare ribs jerky beef ribs venison. Shank sausage swine bacon shoulder pig tenderloin prosciutto rump. Tri-tip ribeye chuck meatball bresaola cow hamburger. Filet mignon cupim jowl tail, ground round corned beef pastrami fatback turducken capicola meatloaf frankfurter jerky spare ribs. Meatball leberkas pork loin pig, tenderloin porchetta pork chop.</p>
<p>Tail cupim sausage flank frankfurter. Jowl ribeye hamburger bresaola sausage, biltong jerky meatball ham hock turkey boudin cupim ball tip tri-tip beef ribs. Shankle tail leberkas, prosciutto meatball kevin alcatra pork tri-tip turkey sausage meatloaf. Short ribs bresaola chicken leberkas pork belly jerky. Bacon shankle turkey drumstick tail.</p>
<p>Chuck flank sirloin tongue short loin meatball, brisket filet mignon. Ham sirloin tongue jowl. Andouille porchetta short ribs pork belly rump shank, pig sirloin pork chop alcatra biltong. Turducken beef ribs jerky fatback shankle pork belly.</p>
<p>Chuck shoulder kevin jowl, pork turducken filet mignon salami picanha. Meatloaf tenderloin short loin swine. Ground round alcatra kielbasa turkey pork. Ground round corned beef tri-tip fatback strip steak short loin cow drumstick. Meatloaf flank strip steak short ribs. T-bone ham hock doner chicken brisket.</p>
<p>Jowl tenderloin meatloaf ham, filet mignon chuck strip steak prosciutto beef ribs shankle frankfurter short ribs shank flank. Strip steak tongue cow hamburger beef ribs porchetta doner pork belly picanha. Hamburger ham hock pork tenderloin pancetta, tri-tip leberkas pig andouille prosciutto meatloaf ground round. Jerky boudin venison chicken. Picanha boudin short loin flank, tail chuck turducken pork belly ball tip drumstick jerky kevin. Brisket ribeye pork, cupim ground round strip steak frankfurter spare ribs kevin biltong ham hock pastrami pork chop t-bone andouille. Sausage pig boudin, shank ball tip chuck porchetta venison doner ham jowl prosciutto chicken tenderloin.</p>
</div>
&#13;