Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A span can be a div, but a div can't be a span

Tags:

css

I'm wondering if that (my title) is ever incorrect, other than for HTML validation. I've recently had to start supporting IE7 again (I've been lucky enough to not have to for the past 3 years or so) and the fact that div's can't be inline-block has gotten me about 10 times in the past month due to the fact that I make everything a div by default and then go back and stylize elements. So I'm considering making everything a span so that if I later go back and make something inline-block I'm not trying to figure out why it's not working in IE7.

So my question -- Is there ever a case, in any browser (IE7+, FF, Webkit, Opera), that anyone knows of where a span can not act like a div? I'm not concerned about the HTML not validating due to having block elements inside inline ones.

like image 500
Nobody Avatar asked Jul 07 '11 17:07

Nobody


People also ask

Can a div be in a span?

The phrasing elements can only contain other phrasing elements, for example, you can't put div inside span.

Is span same as div?

Span and div are both generic HTML elements that group together related parts of a web page. However, they serve different functions. A div element is used for block-level organization and styling of page elements, whereas a span element is used for inline organization and styling.

Can you have a span in a span?

Yes. You can have a span within a span .


1 Answers

I'm not going to directly answer your question, but I think this is worth saying.

I've recently had to start supporting IE7 again (I've been lucky enough to not have to for the past 3 years or so) and the fact that div's can't be inline-block has gotten me about 10 times in the past month

You can use display: inline-block in IE7 for block-level elements such as divs, with:

selector {
    display: inline-block;
    *display: inline;
    zoom: 1
}

If you don't want to use an invalid but safe CSS hack (*property), you can use conditional comments.

like image 180
thirtydot Avatar answered Oct 26 '22 12:10

thirtydot