Oliver
Oliver

Reputation: 2212

No newline after div?

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?

Upvotes: 61

Views: 136382

Answers (8)

Shah Hassan
Shah Hassan

Reputation: 146

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.

Upvotes: 4

user2231096
user2231096

Reputation: 41

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

.div_class {
    clear: left;
}

Upvotes: 0

Jonas
Jonas

Reputation: 1573

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>

Upvotes: 3

Mateen Ulhaq
Mateen Ulhaq

Reputation: 27201

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>.

Upvotes: 9

jerluc
jerluc

Reputation: 4316

<div style="display: inline">Is this what you meant?</div>

Upvotes: 22

Matthew Sant
Matthew Sant

Reputation: 1631

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

Upvotes: 40

alex
alex

Reputation: 490213

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.

Upvotes: 95

Andrew
Andrew

Reputation: 12422

div.noWrap {
    display: inline;
    }

Upvotes: -1

Related Questions