A different approach to achieving a newspaper-like text justification in HTML

When I have a paragraph with text-align:justify, the spacing between words can become uneven due to certain words. I used to rely on the property text-justify:newspaper; which helped break up the words for more evenly spaced text, but unfortunately, it is only supported by IE. Are there any alternatives to achieve this effect in other browsers?

Alternatively, what is the best way to justify text without relying on the text-justify:newspaper; property.

View the Fiddle Here

Answer №1

HTML :

    <div class="pad1" style="width:190px;">
        <h2 class="center">Discover the Reason</h2>
        <p style="word-spacing: 2px;">Our unique approach involves seamless communication between our clients and execution team. Once a project request is received, it is promptly entered into the system and assigned a project code.<b></b></p>
        <div class="wrapper center">
            <a class="button" href="users/About#reason"><span><span><font style="margin-top:1px;"><cufon class="cufon cufon-canvas" alt="Learn More" style="width: 51px; height: 20px;"><canvas width="63" height="25" style="width: 63px; height: 25px; top: -3px; left: -1px;"></canvas><cufontext>Learn More</cufontext></cufon></font></span></span></a>
        </div>
   </div>

You could consider using word-spacing: 2px; instead of

text-align: justify; text-justify: newspaper;
for better results.

Answer №2

When using the text-justify: newspaper setting, words are not broken apart; instead, extra spacing is added between letters of a word to achieve justification. Most browsers do not support this feature (except IE), which means there is limited control over the justification process. Typically, additional spacing between words is the only result.

To improve the appearance of justified text, it's recommended to enable word hyphenation in browsers. This helps reduce the need for excessive spacing. One popular method for achieving hyphenation across different platforms is by implementing JavaScript-based hyphenation on the client-side, such as utilizing Hyphenator.js.

Answer №3

Give this a shot, it helps control the spacing to prevent word separation.

.aligned{
  text-align: justify;
  word-spacing: -1.5px;
}

<p class="aligned">Lorem ipsum</p>

Answer №4

To address your specific situation, the most effective approach would be to maintain text-align:left; while also setting a fixed width (either in percentage or pixels) to achieve your desired outcome.

For Example,

element.style {
    text-align: left;
    width: 250px;
}

Try It Out Here

Hopefully, this explanation is beneficial for you.

Please note: the value of width: 250px; is just an example. Feel free to adjust it based on your own requirements.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The feature of option display is not supported on Safari browser

I am facing an issue with the functionality of two dropdown menus. The options in the second dropdown are supposed to be shown based on the selection made in the first dropdown. While this feature works perfectly in Chrome, it seems to be malfunctioning i ...

What is the best way to align a tweet in the middle of

When using Twitter to embed a tweet, the code provided is necessary. An example of this can be seen below: <blockquote class="twitter-tweet"><p>NoSQL space gradually becoming SlowSQL space.</p>&mdash; Big Data Borat (@BigDataBorat) & ...

Cease the act of sending submissions through JavaScript ajax requests

I need to prevent a form submission based on the result of an ajax request... Here is the code I attempted to implement: The chreg() function is supposed to return a boolean value from the ajax request, but it's not working! Javascript: function ch ...

What is the method for entering text into a Code Mirror line using Selenium?

When I use IE to enter text into a CodeMirror-line text box, the text disappears when I try to save it. I have attempted using JavascriptExecutor to write to the CodeMirror, but it seems to only be for visual purposes. How can I input text into the code mi ...

Can <p> be utilized without creating empty space at the top or bottom?

Is there a way to use paragraph breaks without any space at the top or bottom when there's no text above or below it? body { font-family:arial; background:#222; } #wrapper { width:100%; margin-top:100px; } .post_container { ba ...

Error message displayed on PHP web page

I'm working on a page that will display "no query string" if $_REQUEST is null, and if not, it will show a page with the content saying "query string". Additionally, it should output the line "The query string is: var_dump($_REQUEST)". I've writt ...

PHP not receiving POST information from $.ajax call

My JavaScript triggers a POST method when the datepicker loses focus, calling the script rent-fetch-pick-up-point.php. However, the PHP script gets stuck at the if-statement because it's not receiving the POST data. The datepicker is associated with a ...

Ways to display text when hovering over an image link

Despite trying various techniques recommended by fellow Stackoverflow users who faced similar issues, I still encountered a problem where the text appeared below the image even after applying the suggested methods to my code. I also experimented with a me ...

Make the text within the CSS style of ".well" wrap around the width

I am looking to style the width of a .well class to be in proportion with the text inside a simple textbox that it contains. What is the best approach to achieve this sizing using CSS? ...

Converting a JavaScript object into HTML output

I have received the following JSON data: [    {       "fields": {          "url": "http://www.domain_name.co.uk/MP3/SF560783-01-01-01.mp3\n",          "track_name": "Lion City ",          "release_id": 560783,    ...

What is the best way to vertically center an item at the end of a card in Bootstrap 4?

In the process of creating a long bootstrap card containing two rows of information including a title and description, I encountered an alignment issue with the button. The button is intended to be aligned to the right of the card while remaining centered. ...

Obtain the option tag's name

One of my challenges is working with a dynamically created dropdown in HTML and having a dictionary in the back-end to retrieve keys. As users keep adding options to the dropdown, I face the issue of not having a value attribute like this: <option valu ...

Foundation Framework sidebar by Zurb

My current dilemma involves the zurb foundation framework, specifically with the .row class being set to a max-width of 61.25em, which is equivalent to 980px in width. The problem I am facing is that when I resize the browser and it reaches 1024px wide, t ...

Tips for assigning a class to an Angular accordion header when the panel is in the open state

I am currently utilizing the Angular UI Bootstrap accordion feature, which can be found here. <div ng-controller="AccordionDemoCtrl"> <div accordion close-others="oneAtATime"> <div accordion-group heading ...

Guide on displaying link parameter information on a separate webpage using only JavaScript

While doing some research, I came across an issue. I have a page called specifications.html with three links: details.html?id=1, details.html?id=2, and details.html?id=3. My goal is to display the details of each link when someone clicks on it. For examp ...

Error in height calculation due to setting the CSS property line-height

I am facing a challenge in setting the height of a parent ul element based on the included li's. The issue arises when the CSS property line-height contains fractional digits, causing inaccuracies in the calculation. This results in the calculated hei ...

Background image design for mobile using Bootstrap

On my website, I have a background image set. However, I noticed that when viewing it on a mobile device, the background image appears in different sizes on different pages, even though they are all linked to the same stylesheet and use the same code. You ...

I'm curious as to why a webpage tends to load more quickly when CSS files are loaded before script files. Can anyone shed some

While watching a video, I came across some concepts that were a bit difficult for me to grasp. The video mentions that scripts are 'serialized' and can block subsequent files from loading. According to this explanation, Script 1 would load first ...

fewer security personnel leads to a higher success rate

I've tried searching for it online, but unfortunately, I couldn't find any helpful results. What I'm attempting to achieve is a mixin that can lighten or darken a color based on a given percentage. If the percentage is less than 0, then I w ...

What could be causing the value not to display in my range slider thumb tooltip?

In a recent project of mine, I implemented a range slider with two thumbs - one for setting the minimum value and one for the maximum value. The goal was to provide users with a visual representation of the range they are selecting by displaying the thumb ...