Solved

CSS Text Justification

Posted on 2008-10-25
5
740 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

803 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