How to display <div> inline surrounded with text?

16,659

Solution 1

There's a CSS property display: inline-block; but I don't know how compatible with browsers it is (works fine in my FF)

I'll do some quick testing for you.

Update

I've tested it in Chrome, FF and IE. Works in IE8, not IE7. Chrome is fine as is FF

Solution 2

Basically just add display: inline-block; You might want to tune it a bit afterward, but this should work everywhere except IE6

Share:
16,659
rafalry
Author by

rafalry

Updated on June 04, 2022

Comments

  • rafalry
    rafalry about 2 years

    I would like to display a <div> element inline so that it is surrounded with text.

    My code is:

    <span>Here is some <div class="a"></div> text</span>
    

    Let's say, the class "a" is defined as below:

    .a {
        width:20px;
        height:20px;
        background-color:#f00;
    }
    

    The result should be like this:

    alt text

    Is it doable? Thank you for any suggestions.

  • Flipke
    Flipke over 13 years
    Works in safari, chrome, opera, FF, IE8, won't work in IE6/IE7 though
  • oezi
    oezi over 13 years
    inline-block doesn't work (or doesn't work correct) in IE6/7, but theres a hack for that if you have to support them: homepage.ntlworld.com/spartanicus/…