简体   繁体   English

调整div内容宽度以在多行上显示内容

[英]adjusting div content width to display content on multiple lines

在此处输入图片说明 i have a div tag <div id="pageNo"></div> for displaying the pagination numbers. 我有一个div标签<div id="pageNo"></div>用于显示分页号。 well it's displaying the numbers 1,2,3,4,..25(it's dynamic, not always 25) in one line from left end of the page to right end. 从页面左端到右端的一行中显示数字1,2,3,4,.. 25(它是动态的,并不总是25)。 I want the numbers to switch to next line where the table's width ends. 我希望数字切换到表格宽度结束的下一行。 the table is the one under which these numbers are displayed and it has the width of 1100px. 该表格是显示这些数字的表格,其宽度为1100像素。 I did something like this : <div id="pageNo" style="width: 700px"></div> . 我做了这样的事情: <div id="pageNo" style="width: 700px"></div> And it did not work. 而且它没有用。 So all am looking for the the css to achieve that. 因此,所有人都在寻找实现这一目标的CSS。 For example, it should switch to new line after displaying 10 numbers 例如,显示10个数字后应切换到新行

If the parent container has a fixed width and you want to control how many numbers are displayed per line, you can wrap the numbers with divs and set a fixed width: 如果父容器的宽度固定,并且您希望控制每行显示多少个数字,则可以用div包裹数字并设置固定宽度:

 .parent { background-color: grey; width: 500px; } .parent div { background-color: white; margin: 1px; width: 50px; display: inline-block; } 
 <div class="parent"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> <div>6</div> <div>7</div> <div>8</div> <div>9</div> <div>10</div> <div>11</div> <div>12</div> <div>13</div> <div>14</div> <div>15</div> </div> 

You could try and set word-wrap 您可以尝试设置word-wrap

Something like this: 像这样:

<div id="pageNo" style="width: 700px; word-wrap: break-word;">
1 2 3 4......
</div>

Check out this fiddle: https://jsfiddle.net/9Ln3h3L2/1/ 看看这个小提琴: https : //jsfiddle.net/9Ln3h3L2/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM