Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent DIV tag starting a new line?

Tags:

html

css

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?

like image 512
undefined Avatar asked Dec 01 '09 14:12

undefined


People also ask

Does div always start new line?

It is an inline-level element and does not break to the next line unless its default behavior is changed. To make these examples easier to use and understand for all types of computer users, we're using the style attribute in the div.

How do you not break a line after div?

display:inline; will turn the div into the equivalent of a span . It will be unaffected by margin-top , margin-bottom , padding-top , padding-bottom , height , etc.

How do I keep a div on the same line?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.

How do you stop an element from going to the next line?

Inline elements behave in much the same way as text does. If you want to prevent them from wrapping, either remove the white space you have used for formatting, or add white-space:nowrap; to the rule for .


2 Answers

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)

like image 80
SLaks Avatar answered Oct 01 '22 13:10

SLaks


I am not an expert but try white-space:nowrap;

The white-space property is supported in all major browsers.

Note: The value "inherit" is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports "inherit".

like image 21
Shivanshu Avatar answered Oct 01 '22 12:10

Shivanshu