Solved

CSS Text Justification

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS: Making responsive table look nicer 7 37
How to format numbers and letters in nested lists 5 41
Bootstrap 3 - Style a dropdown 1 25
CSS for <center> 14 33
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 …
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 position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

740 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