简体   繁体   English

CSS页面布局w / Breaks

[英]CSS Page Layout w/ Breaks

I'm trying to make a webpage where it basically looks like a word document. 我正在尝试创建一个基本上看起来像word文档的网页。 There would be multiple boxes that would scroll down and the text would flow and page break from one page to the next. 将有多个框向下滚动,文本将从一个页面流向另一个页面。

Does anyone have any idea where I would even start? 有谁知道我甚至会在哪里开始? Thanks. 谢谢。

Edit: It should be right in the browser, looking similar to this: 编辑:它应该在浏览器中,看起来类似于:

在此输入图像描述 (Ignore the columns) (忽略列)

CSS mostly applies styles to a full element due to its box model . 由于其盒子模型, CSS主要将样式应用于完整元素。 Exceptions are pseudo elements . 例外是伪元素 So to create an appropriate break after a fixed length you would have to separate your text into correctly sized different elements. 因此,要在固定长度之后创建适当的中断,您必须将文本分成正确大小的不同元素。

EDIT: It would be possible using javascript. 编辑:可以使用javascript。 But even in the simplest case, where everything inside the pages delivered as just one text element with no sub elements (not even other text elements), the code will be a development nightmare and will run quite crappy. 但即使在最简单的情况下,页面内的所有内容都只作为一个没有子元素的文本元素(甚至不是其他文本元素)提供,代码将成为一个开发的噩梦,并且会运行起来很糟糕。 This is because there is no measure function in javascript. 这是因为javascript中没有测量功能。 So you would be forced to do trail and error to find the correct position to break the element. 所以你将被迫做出追踪和错误来找到正确的位置来打破元素。 Since the properties of the elements are live it means, that the viewer of the website will see a lot of flickering of your page just after loading. 由于元素的属性是实时的,这意味着网站的查看者在加载后会看到很多页面的闪烁。 If you dare put other elements inside the html element to break into pages you get even more problems. 如果你敢把html元素中的其他元素放入页面中,你会遇到更多问题。 More or less you get hundreds of special cases (break inside other elements, what if those elements are inside even other elements) to look out for. 或多或少,你会得到数以百计的特殊情况(在其他元素内部,如果这些元素在其他元素内部则会被破坏)。

<p style="page-break-before: always">This would print on the next page</p>

Something like that sounds possible using javascript, but it depends a bit on the structure of your html and whether or not you want to break paragraphs or just move the next paragraph to the next page if it doesn´t fit 使用javascript听起来有点像这样的东西,但它取决于你的html的结构以及你是否要打破段落或者如果它不适合将下一段移动到下一页

So the simplest example, not breaking paragraphs / html elements with a flat html structure (no nested divs, columns, etc) like: 所以最简单的例子,不要破坏带有平面html结构的段落/ html元素(没有嵌套的div,列等),如:

<div class="document">
  <h1>title</h1>
  <p>texts</p>
  <h2>subtitle</h2>
  <p>texts</p>
  ...
  <p>texts</p>
</div>

would be to do something like: 会做的事情如下:

height = 0
loop through all direct child elements of .document
{
    if ( (height + element_height) > page_height)
    {
        add page_break_element before current element
        height = 0
    }
    height = height + element_height
}

I´d use jquery because it makes it easy to loop through the elements, measure heights, etc. 我使用jquery,因为它可以很容易地循环元素,测量高度等。

I guess breaking paragraphs would be possible as well, but a lot of extra work. 我想破坏段落也是可能的,但还有很多额外的工作。

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

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