2

Is it possible to declare CSS for a div, so that the declared div will be shown inside a line of text? E.g. a span can be shown inside text, but how about div? See below or here for an example.
Thanks in advance

This is a * * * Text-Test! * * * 
This is a * * * Text-Test! * <span style="position:absolute; width:200px; color:#FF0000; float:left;"><b>This Span is inside the text or line.</b></span>* * This is a * * * Text-Test! * * *<br/>
This is a * * * Text-Test! * * * This is a * * * Text-Test! * * *<br/>
This is a * * * Text-Test! * <div id="Helper" style="position:absolute; background-color:#00FF00; width:100px; height:20px; float:right;">*** This DIV is at the beginning of the text or line. *** </div>* * This is a * * * Text-Test! * * * <br/>
This is a * * * Text-Test! * * * This is a * * * Text-Test! * * *
NissimL
  • 148
  • 8
user3815508
  • 369
  • 4
  • 20

3 Answers3

2

You need to use display:inline in css. Here is the link to the fiddle

Try like this: Hello <div style="display:inline;">World!</div> How are you?

Ruchir Gupta
  • 990
  • 3
  • 10
  • 20
2

As per the following answer, inline div elements should be avoided if possible, as they are not valid. Use span instead.

https://stackoverflow.com/a/1611079/2359161

Community
  • 1
  • 1
Alex Podworny
  • 1,018
  • 1
  • 14
  • 25
1

div is a block level element. Means it always starts and end with new line when displayed in browser Also we use divs when we want to give style to group of elements.For Example

<html>
<div>
<h1>StackOverflow</h1>
<p>welcome to stackOverflow</p>
</div>

Now in above example we group together two html elements. if you still want to use div as inline block element. You have to do one thing

div{
  display:inline;
}

Now when you set property to inline it behaves like inline block element.Now your div will accepts margin and padding but it still remain inline.Margin and padding will only push other elements horizontally but not vertically

div{
display:inline-block;
}

but if you div property to inline-block, then you can set width and height of element and it still remain inline.

for more information [http://css-tricks.com/almanac/properties/d/display/]

Sanjay Dutt
  • 2,192
  • 16
  • 16