CSS 和打印:将文本块保持在一起

发布于 2024-08-18 03:56:33 字数 710 浏览 9 评论 0原文

这是典型的多项选择题考试,假设问题格式:

<question qid='1'>
<stem>What is your name?</stem>
<choice value = 'a'>Arthur, King of the Britons</choice>
<choice value = 'b'>There are some who call me ... Tim!</choice>
<choice value = 'c'>He is brave Sir Robin, brave Sir Robin, who-- Shut up! Um, n-- n-- n-- nobody, really. I'm j-- j-- j-- ju-- just, um-- just passing through.</choice>
<choice value = 'd'>Sir Galahad... the Chaste.</choice>
<choice value = 'e'>Zoot... Just Zoot.</choice>
</question>

我已经将所有这些都映射到带有网络单选按钮的适当样式。

现在,我需要制作测试的可打印版本。这实际上更简单,因为我不需要包含无线电,只需“___”作为复选标记。主要问题是如何防止问题因分页符而分裂。

This is a typical Multiple Choice exam, Assume a question format:

<question qid='1'>
<stem>What is your name?</stem>
<choice value = 'a'>Arthur, King of the Britons</choice>
<choice value = 'b'>There are some who call me ... Tim!</choice>
<choice value = 'c'>He is brave Sir Robin, brave Sir Robin, who-- Shut up! Um, n-- n-- n-- nobody, really. I'm j-- j-- j-- ju-- just, um-- just passing through.</choice>
<choice value = 'd'>Sir Galahad... the Chaste.</choice>
<choice value = 'e'>Zoot... Just Zoot.</choice>
</question>

and I've got this all mapped to appropriate styles with radio buttons for the web.

Now, I need to make a printable version of the test. This is actually simpler, in that I don't need to include radios, just '___' for a check mark. The major issue is how to keep the question from splitting over the page break.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千紇 2024-08-25 03:56:33

我从来没有幸运地持续阻止类似的事情发生。这可能有点脏,但如果问题通常长度相同,您可以在每 X 个问题之后强制分页吗?

<style type="text/css">
.pageBreak{
    page-break-before: always;
}
</style>

<question>...</question><br class="pageBreak" />
<question>...</question>

(或者将该类应用于问题或任何您想要的)

您可以尝试使用 page-break-inside 属性,但我还没有看到它是一致的,因为浏览器对它的支持现在很混乱:

question {
    page-break-inside:avoid;
}

I haven't ever had luck with consistently preventing something like that. It may be a bit dirty, but if the questions are usually of the sameish length can you force a page-break after every X questions?

<style type="text/css">
.pageBreak{
    page-break-before: always;
}
</style>

<question>...</question><br class="pageBreak" />
<question>...</question>

(Or apply that class to the question or whatever you want)

You can try using the page-break-inside property, but I haven't seen it be consistent as browser support for it is a mess right now:

question {
    page-break-inside:avoid;
}
喜你已久 2024-08-25 03:56:33

我建议您查看 page-break-afterpage-break-insidepage-break-before CSS 中的规则。

I'd suggest you look into page-break-after, page-break-inside and page-break-before rules in CSS.

勿忘初心 2024-08-25 03:56:33

使用单独的打印样式表,并使用 page-break-beforepage-break-after 选择器来设置每页上的开头和结尾问题。

如果测验是静态的,您可以绘制所使用的类并使其正常运行,而无需任何 CSS 之外的东西。

Use a separate print stylesheet, and use the page-break-before and page-break-after selectors for your leading and ending questions on each page.

If the quiz is static, you can plot the classes you use out and make it work without anything more than CSS.

忆伤 2024-08-25 03:56:33

使用表格布局。但为了避免改变语义,请使用 CSS。

question {
    display: inline-table;
} 

Use a table layout. But to avoid changing the semantics, use CSS.

question {
    display: inline-table;
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文