I'm trying to make a pre to limit the width size that does not exceed the table, try using this tag:
<?php
echo "<pre style='max-width:1px;'>".$long_string."</pre>";
?>
both the <pre>
and the table but does not work in any case.
anyone can help me?
The <pre> tag defines preformatted text. Text in a <pre> element is displayed in a fixed-width font, and the text preserves both spaces and line breaks. The text will be displayed exactly as written in the HTML source code.
The difference between width: 100% and max-width:100% is that: First, width define the width of specific element while max-width define the maximum size the element is allow to have.
<pre>: The Preformatted Text element. The <pre> HTML element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered using a non-proportional, or monospaced, font. Whitespace inside this element is displayed as written.
While the font-size cannot be changed for text directly inside pre tags, you can always wrap that text in another element (a span, for example) and change the font size of that element.
Setting max-width
on a pre
element actually restricts it width. You can see this by inspecting the element using a browser’s Developer Tools and also simply by setting a background color on it, say pre { background: yellow }
. Note: testing this with the outline
property gives a wrong result in Firefox; but even it implements the border
property correctly.
As usual in rendering elements, content may overflow the width of the element, and the default is visible overflow. If you wish to cut it off, rendering just the part that fits in, set pre { overflow: hidden }
. If you wish to indicate truncation with an ellipsis “…”, set also pre { text-overflow: ellipsis; }
.
If you would want to make long lines wrap when needed to make the content fit, you can instead set pre { white-space: pre-wrap }
. However, long strings without spaces could still cause overflow. This can be prevented by adding pre { word-wrap: break-word; }
(old syntax) or pre { overflow-wrap: break-word; }
(new syntax, with slightly more limited browser support).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With