255

Here is the story: I'm using SWFObject to insert a Flash object into my page. The embedding eats my span. So, I lose all my CSS for it. I was thinking of moving all of the CSS to the parent so I don't lose my CSS styles when the Flash appears.

I have tried using a span within a span, but I don't think it's working. Is there a reason for this? I don't understand why you could have div within a div but not a span within a span.

Does it have to do with spans being inline?

8
  • 37
    You can have a span within a span
    – SLaks
    Feb 1, 2012 at 2:36
  • 1
    What do you mean by: "embedding eats my span". Also, please provide a reduced test case on dabblet or Jsfiddle.
    – bookcasey
    Feb 1, 2012 at 2:38
  • 1
    A span isn't any different than a div except that by default the properties of each tend to be defined a certain way. However, they're both just elements. You could view a span as a block level element if you chose to do so. I think you're using the embed method incorrectly. I believe swfObject asks you to define an element for it to replace the contents of. Their example here: code.google.com/p/swfobject/wiki/documentation shows them replacing an object. Maybe you should do the same.
    – Kai Qing
    Feb 1, 2012 at 2:41
  • 2
    For anyone that comes across this question. Keep in mind that you might need to set your span to position: block or position: inline-block if you need to add styling.
    – JGallardo
    Dec 13, 2016 at 22:37
  • 2
    @JGallardo you mean display: block or display: inline-block. Jun 29, 2018 at 21:56

2 Answers 2

416

HTML4 specification states that:

Inline elements may contain only data and other inline elements

Span is an inline element, therefore having span inside span is valid. There's a related question: Can <span> tags have any type of tags inside them? which makes it completely clear.

HTML5 specification (including the most current draft of HTML 5.3 dated November 16, 2017) changes terminology, but it's still perfectly valid to place span inside another span.

207

Yes. You can have a span within a span. Your problem stems from something else.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.