tags:

views:

253

answers:

5

I want to output a single line of text to the browser that contains a tag. When this is rendered it appears that the DIV causes a new line. How can I include the content in the div tag on the same line - here is my code.

<?php 
  echo("<a href=\"pagea.php?id=$id\">Page A</a>") 
?>
<div id="contentInfo_new">
  <script type="text/javascript" src="getData.php?id=<?php echo($id); ?>"></script>
</div>

I have tried to tidy it up here. How can I have this display on a single line?

thanks

+11  A: 

div is a block element, which always takes up its own line.

use the span tag instead

cobbal
You are confusing presentation for function. A div takes up its own line because it is presented as display:block by default and for no other reason.
+1  A: 

use float:left on the div and the link, or use a span.

Jimmeh
+1  A: 

Add style="display: inline" to your div.

Franz
Actually, do what cobbal suggested and use the `span` tag instead.
Franz
A: 
<div style="float: left;">
<?php 
  echo("<a href=\"pagea.php?id=$id\">Page A</a>") 
?>
</div>
<div id="contentInfo_new" style="float: left;">
  <script type="text/javascript" src="getData.php?id=<?php echo($id); ?>"></script>
</div>
dfilkovi
+7  A: 

The div tag is a block element, causing that behavior.

You should use a span element instead, which is inline.

If you really want to use div, add style="display: inline". (You can also put that in a CSS rule)

SLaks
Only `display: inline` contradicts what the DIV is for, so please don't do it! Use the span instead.
The Wicked Flea
I'm well aware of that; that's why I wrote `if you really want to`.
SLaks
A div is defined as a division of a page, prior to HTML5. Its not defined with any presentation characteristics. In other words a div is semantically appropriate according to its definition based upon the content and elements it contains. As a result it is perfectly fine to set a div to display:inline and not violate any semantics or standard definition.