Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display <div> inline surrounded with text?

Tags:

html

css

inline

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.

like image 817
rafalry Avatar asked Nov 23 '10 13:11

rafalry


People also ask

How do I display the content of an inline div?

Users can see that all div elements inside the parent div are displaying inline. Approach 2: In this approach, we will apply display: inline-block property to all the div which we need to display inline. The display:inline-block property will set the all div elements side by side.

Does text align work on inline elements?

Even though the property says “text” align, it affects all elements inside the block-level element that are either inline or inline-block elements. The property only affects the content inside the element to which it is applied, and not the element itself.

How do I display a div element horizontally?

To align div horizontally, one solution is to use css float property. But a better solution is to to use CSS display:inline-block on all divs which needs to be aligned horizontally and place them in some container div.

How do you make an inline element act like a block element?

You can change the visual presentation of an element using the CSS display property. For example, by changing the value of display from "inline" to "block" , you can tell the browser to render the inline element in a block box rather than an inline box, and vice versa.


2 Answers

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

like image 146
Psytronic Avatar answered Oct 08 '22 06:10

Psytronic


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

like image 23
Flipke Avatar answered Oct 08 '22 05:10

Flipke