3 replies [Last post]
Warped
Offline
newbie
Last seen: 10 years 34 weeks ago
Joined: 2004-02-26
Posts: 2
Points: 0

Hello. I have a loop of code that displays the name and description of an element. Everything works fine unless one of the text fields is longer than the specified css width. The text will wrap, which is great, however, when it loops around to display the next element it writes the text on the same line. Shouldn't a text wrap automatically place a <br> tag in the html?

below is the code written in PHP.

foreach ($viewSeries as $key) {
?>
<div id="tblLeft">Name:</div>
<div id="tblRight"><? echo htmlspecialchars($key['Name']); ?></div>
<br />
<div id="tblLeft">Description:</div>
<div id="tblRight"><? echo $key['Description']; ?></div>
<br />
<?
}

below is the css file for tblLeft and tblRight.

#tblLeft {
position: absolute;
margin: 0px 0px 0px 3px;
width: 150;
text-align: right;
font-weight: bold;
padding-right: 5;
background-color : #DDD;
border-bottom: 1px solid #222;
border-top: 1px solid #BBB;
}
#tblRight {
position: absolute;
margin: 0px 0px 0px 162px;
width: 500;
text-align: left;
font-weight: normal;
color: #222;
white-space: -moz-pre-wrap;
}

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 6 hours 11 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5125
Points: 2722

CSS DIV tags not going to next line

Hi Warped,
Try changing the position values to relative.
Could you link to an example if you are still having problems.

dJomp
dJomp's picture
Offline
Enthusiast
York, England
Last seen: 11 years 31 weeks ago
York, England
Joined: 2003-03-23
Posts: 422
Points: 0

Re: CSS DIV tags not going to next line

Warped wrote:
Shouldn't a text wrap automatically place a <br> tag in the html?

No, unfortunately htmlspecialchars isn't that clever... since the width is in a CSS file, and the PHP code doesn't have anything to do with it. However the rendering of the page should do what you want if you follow Tony's advice.

You know you're a geek when you try to shoo a fly away from the monitor with your cursor.

Warped
Offline
newbie
Last seen: 10 years 34 weeks ago
Joined: 2004-02-26
Posts: 2
Points: 0

THAT WORKED!!!!

tony thank you so much. that worked perfectly.