Solved

CSS Text Justification

Posted on 2008-10-25
5
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

734 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