Is it possible to recreate the exact look and feel of a justified page from a book or article online using HTML/CSS? This would include replicating the text justification with precise line breaks and setting the outer wrapper width to match the min/max-width of the text itself.
An example HTML structure could be:
...
<div class="page-wrapper">
<span class="line">The Republic of Plato is the longest of his works with the exception of the Laws,</span>
<span class="line">and is certainly the greatest of them. There are nearer approaches to modern</span>
<span class="line">metaphysics in the Philebus and in the Sophist; the Politicus or Statesman is</span>
<span class="line">more ideal; the form and institutions of the State are more clearly drawn out</span>
</div>
...
Note 1:
While this CSS-trick may work for specific scenarios, it has limitations as it relies on the rendering engine. The fixed width (e.g., 500px
) can cause issues such as premature breaklines or excessive word-spacing. It may not be scalable across different devices.
.page-wrapper {
text-align: justify;
width: 500px;
}
.line:after {
content: "";
display: inline-block;
width: 100%;
}
Note 2: Ideally, I'm looking for a pure HTML/CSS solution. If that's not achievable, we might need to consider JavaScript...