Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert div to span with CSS

Tags:

I have a few divs which makes a little bit too spacey between the footer and the body. So i want to convert one div to a span. But when I do that, it messes the footer's content a bit up.

How can i do this and keep the styles that already have been defined for the footer?

Thanks in advance!

Edit

div.footer { width: 986px; margin: 0 auto; padding-bottom:18px; border: 0; text-align: left; color:#000000; } 
like image 334
Yustme Avatar asked Sep 29 '10 09:09

Yustme


People also ask

Can CSS be applied to span?

You can use the HTML span tag as a container to group inline elements together so you can style or manipulate them with JavaScript.

Can div contain span?

It should be used only when no other semantic element is appropriate. <span> is very much like a <div> element, but <div> is a block-level element whereas a <span> is an inline element.


2 Answers

As you already know, the difference between a <div> and a <span> is just that one defaults to display:block; and the other to display:inline;. To make one act as the other, just set the display style to the other type.

However, you already said you tried this and it didn't achieve the effect you were looking for. There is another display property, which is less well known, but provides a half-way house between the two:

display:inline-block; 

What it does is display it inline, but still with block-like properties. (This is basically how an <img> tag works by default).

Could this be the answer you're looking for?

like image 189
Spudley Avatar answered Oct 21 '22 03:10

Spudley


To convert a div to a span, simply add:

.myDiv {    display: inline; } 

But I'm really not sure that this is the solution you're after.

like image 24
Kyle Avatar answered Oct 21 '22 03:10

Kyle