60

Is there a way to not have a newline inserted before a div without using float: left on the previous element?

Maybe some tag on the div that will just put it to the right?

alex
  • 479,566
  • 201
  • 878
  • 984
Oliver
  • 2,182
  • 5
  • 24
  • 31

9 Answers9

94

There is no newline, just the div is a block element.

You can make the div inline by adding display: inline, which may be what you want.

alex
  • 479,566
  • 201
  • 878
  • 984
39

Have you considered using span instead of div? It is the in-line version of div.

Matthew Sant
  • 1,611
  • 11
  • 10
22
<div style="display: inline">Is this what you meant?</div>
alex
  • 479,566
  • 201
  • 878
  • 984
jerluc
  • 4,186
  • 2
  • 25
  • 44
9

Quoting Mr Initial Man from here:

Instead of this:

<div id="Top" class="info"></div><a href="#" class="a_info"></a>

Use this:

<span id="Top" class="info"></span><a href="#" class="a_info"></a>

Also, you could use this:

<div id="Top" class="info"><a href="#" class="a_info"></a></div>

And gostbustaz:

If you absoultely must use a <div>, you can set

div {
    display: inline;
}

in your stylesheet.

Of course, that essentially makes the <div> a <span>.

ndsmyter
  • 6,535
  • 3
  • 22
  • 37
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
4

Use span instead of div. Since span is inline element while div is the block element. So div is always going to add into the new line as it covers the entire width while span doesn't.

Shah Hassan
  • 106
  • 5
3

This works like magic, use it in the CSS file on the div you want to have on the new line:

.div_class {
    clear: left;
}

Or declare it in the html:

<div style="clear: left">
     <!-- Content... -->
</div>
Jonas
  • 1,473
  • 2
  • 13
  • 28
0

This works the best, in my case, I tried it all

.div_class {
    clear: left;
}
0

try:

<div style="padding: 50px; background-color: #BCC6CC;">Div one</div>
<div style="padding: 50px; background-color: #E5E4E2;">Div two</div>
AliNajafZadeh
  • 1,216
  • 2
  • 13
  • 22
-1
div.noWrap {
    display: inline;
    }
Andrew
  • 12,172
  • 16
  • 46
  • 61