简体   繁体   English

如何修复css列上溢出的段落标签?

[英]How to fix a paragraph tag overflowing on css column?

I have to make a responsive text that looks like a book.我必须制作一个看起来像一本书的响应式文本。 It means that the texts has to be in the same place doesn't matter how big screen is.这意味着无论屏幕有多大,文本都必须在同一个地方。 I'm trying to use columns, but I can't even make the p tag stay inside screen.我正在尝试使用列,但我什至不能让 p 标签留在屏幕内。

 .page { background-color: #fff; width: 100%; height: 141.43vw; margin-bottom: 10px; overflow: hidden; } .text-column { text-align: justify; column-count: 2; }
 <section class="page text-column"> <article> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio eos placeat aliquid rem neque maxime animi repellat in molestias quos asperiores odit reprehenderit eaque quod commodi, esse mollitia dolor quidem. </p> </article> </section>

edit: added img编辑:添加了img

从浏览器打印屏幕

Can you please try with "column-count: 2;"你能试试“列数:2;” to 'p', because you can not directly apply this css to super parent of the desired element.到“p”,因为您不能直接将此 css 应用于所需元素的超级父级。

 .page { background-color: #fff; width: 100%; height: 141.43vw; margin-bottom: 10px; overflow: hidden; } .text-column p { text-align: justify; column-count: 2; }
 <section class="page text-column"> <article> <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio eos placeat aliquid rem neque maxime animi repellat in molestias quos asperiores odit reprehenderit eaque quod commodi, esse mollitia dolor quidem. </p> </article> </section>

只需将此添加到您的“p”标签 CSS:

column-count: 2;

Normally, to keep the text in the same position no matter what is the device used you need the keep the text size in place and the column width to have an absolute width , rather than a relative one.通常,无论使用什么设备,为了将文本保持在相同的位置,您需要将文本大小保持在适当的位置,并且列宽具有绝对宽度,而不是相对宽度

Assuming that the font size is always the same, you can apply - as the user above said - the column-count: 2;假设字体大小始终相同,您可以应用 - 正如上面的用户所说 - column-count: 2; to the .text-column p and also set a width: 800px;.text-column p并设置宽度:800px; . .

You will have to make the paragraph responsive for devices where the resolution is smaller than 800px.对于分辨率小于 800 像素的设备,您必须使段落响应。 Usually, most devices have a screen size wider than 400px(half of the initial size, but 1 column now).通常,大多数设备的屏幕尺寸都大于 400 像素(初始尺寸的一半,但现在为 1 列)。

The only problem is that whenever the screen width falls below 800px, the paragraph width will instantly transform to a 400px width one.唯一的问题是,当屏幕宽度低于 800px 时,段落宽度会立即转换为 400px 宽度。 The following code will get this result:下面的代码会得到这个结果:

.page {
      background-color: white;
      width: 100%;
      height: 141.43vw;
      margin-bottom: 10px;
      overflow: hidden;
}

.text-column p {
  margin-top: 0px;
  padding: 10px;
  column-count: 2;
  width: 800px;
}

@media only screen and (max-width: 800px) {
  .text-column p {
  column-count: 1;
  width: 400px;
}
}

As I said below, keeping the position of the words exactly the same in a phrase or the page content unchanged no matter the device requires absolute sizes .正如我在下面所说的,无论设备需要绝对大小,保持单词在短语或页面内容中的位置完全相同。 The previously mentioned solution works when the page number is not too relevant.当页码不太相关时,前面提到的解决方案有效。

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

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