Forum Moderators: open
A span is used to group elements so that they can be modified through CSS or accessed by Javascript. Unlike a div, which is block, a span is inline. This far I get.
<p>You have <span id="charstogo">500</span> characters remaining.</p>
<span class="red">Some red text here (assuming red class is defined)</span>
<span style="font-size:36px">Some big text here</span>
You know, I think I figured it out for myself.Loathe to interrupt a good conversation ... ;), but separate structure (HTML) from presentation (css). For example visibility:hidden "presents" html elements as invisible - but they still exist in the document.No. I must be wrong. Because I know that over the css diplay property I can sometimes force a block element to display as an inline element. Hmmm...
Should I imagine a large rectangle that encompasses everything between the span tags of my code? Or a conglomeration of all element containers into a strange orthogonal form? Or, I dunno, a line?Easiest to imagine a rectangle (box) that flows along the "lines" of text.
I guess then maybe spans are just there for being able to group inline elements without ruining their natural flow by putting them in a box.But understanding inline elements can be really helpful, even if not using spans. Chapter 9 and 10 of css 2.1 have lots more detail. I think 9.4.2 [w3.org] best addresses the first question you asked, but also see the explanations about width and height calculations.
The <font color="red>rain</font> in <font size="+1">Spain</font> falls mainly on the <font face="Arial" size="+2" color="green">plain</font>.
The <span class="red">rain</span> in <span class="big">Spain</span> falls mainly on the <span class="lastword">plain</span>.
The <span class="weather">rain</span> in <span class="country">Spain</span> falls mainly on the <span class="terrain">plain</span>.
But the problem for me is that I can't visualize what a span looks like. And maybe because I don't fully understand how inline elements work/flow. A div's easy. It's a box. Anything inside the div goes inside a box. A div clears the page. But a span?
Should I imagine a large rectangle that encompasses everything between the span tags of my code? Or a conglomeration of all element containers into a strange orthogonal form? Or, I dunno, a line?
<div>
The Foo Widget can hold 5 Bar Widgets.
</div>
<div>
The <span class="widget">Foo Widget</span> can hold
<span class="widgetChildren">5</span> <span class="widget">Bar Widgets</widget>.
</div>
The Foo Widget can hold 5 Bar
Widgets.
And what's this about not being allowed to put block elements into a span? Why? I tried spanning over one a using display:none, and this seems to work. Did I do something wrong?
<span>This contains a <div>block</div> element</span>
This contains a
block
element
This contains a block element
I prefer to just use "class=bigger" and be done with it.
A name like "class=red" could end up really strange if you ever decided to make those items blue
A name like "class=red" could end up really strange if you ever decided to make those items blue
<p><span lang="fr">Bonjour</span>, welcome to my website!</p>Becomes
<p><i lang="fr">Bonjour</i>, welcome to my website!</p>As words from other languages are usually italicised if not fully assimilated, and <em> conveys a changed meaning for non-visual users as well.
Or perhaps better
<p><em lang="fr">Bonjour</em>, welcome to my website!</p>
The <span class="red">rain</span> in <span class="big">Spain</span> falls mainly on the <span class="lastword">plain</span>.
p :first-child {color:red}Or if this is a sentence, not a para, then:
p :last-child {color:fuchsia;text-decoration: overline}
<p>The <span>rain</span> in <big>Spain</big> falls mainly on the <span>plain</span>.</p>
span :first-child {color:red;}An example of span as a "container". Give it an id and it becomes a target as well. All without imposing any change of meaning, especially if that creates unneeded "clutter" for non-visual users. And conserves code kb's for those of us who still care.
span :last-child {color:fuchsia;text-decoration: overline}
<span>The <span>rain</span> in <big>Spain</big> falls mainly on the <span>plain</span>.</span>
The <span class="weather">rain</span> in <span class="country">Spain</span> falls mainly on the <span class="terrain">plain</span>.
<p><span lang="fr">Bonjour</span>, welcome to my website!</p>
isn't this what XHTML is for?
isn't this what XHTML is forExactly my thoughts - if you want to invent your own names for elements then xml.
We can give them pseudo semantic value by using class names that describe the content,Fotiman, I don't agree. Class names are for the css. css is for style - not structure, and therefore not document semantics.
We can give them pseudo semantic value by using class names that describe the content,
Fotiman, I don't agree. Class names are for the css. css is for style - not structure, and therefore not document semantics.