Solved

CSS Text Justification

Posted on 2008-10-25
5
720 Views
Last Modified: 2012-05-05
Hello,

Can anyone comment on why the text-align justify part below does not work ?

thanks,

GISVPN
the CSS ...
 

.article_txt{

font-family: Trebuchet MS;

font-size: 14px;

line-height: 15pt;

text-align: justify;

}
 
 

the HTML ...
 

<td width="365"><span class="article_txt">Some TEXT in a CELL</span</td>

Open in new window

0
Comment
Question by:gisvpn
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
jgmontgo earned 250 total points
ID: 22803411
There are a couple of reasons that this is not working:
  • </span should be </span>
  • If the text is shorter than a full line it is not justified, if it is longer it is justified
  • the class needs to be moved to the <td> then the span can be removed
  • The CSS also had a font name that should be in quotes although this is not a serious issue
I have attached a working sample:

@charset "utf-8";

/* CSS Document */
 

.article_txt{

font-family: "Trebuchet MS";

font-size: 14px;

line-height: 15pt;

text-align: justify;

}
 
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="css/test.css" rel="stylesheet" type="text/css" />

</head>

<body>

<table width="365" border="0">

  <tr>

    <td width="365" class="article_txt">Some TEXT in a CELL that is now longer than it used to be but this is really just a testto see what happens when you place more text in the box</td>

  </tr>

</table>

</body>

</html>

Open in new window

0
 

Author Comment

by:gisvpn
ID: 22803695
Great thanks for the info....


</span should be </span> ... sorry my typing error in the post, the original was </span>..

If the text is shorter than a full line it is not justified, if it is longer it is justified ... sorry again, the post just had example text in it, the original had lots of text.

 
the class needs to be moved to the <td> then the span can be removed ... that was the problem ! Moving to the TD made it work. Why did the SPAN method not work ?


The CSS also had a font name that should be in quotes although this is not a serious issue - fixed thanks..
0
 
LVL 42

Expert Comment

by:David S.
ID: 22804137
0
 

Author Closing Comment

by:gisvpn
ID: 31509938
Great thanks for the information. Much appreciated.
0
 
LVL 11

Expert Comment

by:jgmontgo
ID: 22805022
Kravimir is right that "It did not work with the <span> because the <span> is an inline element." If you find the actual usage of text-align: justify it is actually designed to work inside a table. The basic idea is that you have to have a constrained area with a defined right and lest side in order to justify, otherwise the browser would have no idea what to justify against.
Thanks for the points.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now