By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,434 Members | 2,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,434 IT Pros & Developers. It's quick & easy.

span won't honor width... div will, but always have line break before and after

P: n/a
wow... i didn't know that, for
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">

<span style="width: 100px; background: yellow">a</span>b
<div style="width: 100px; background: yellow">a</div>b
1) the a and b will stick together for the first line, so span doesn't
honor the "width: 100px"

2) the div honors the "width: 100px", as the background is shown
yellow. but it will force a line break both before the div and after
the div.

Oct 25 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
rf

"Summercool" <Su************@gmail.comwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
wow... i didn't know that, for
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">

<span style="width: 100px; background: yellow">a</span>b
<div style="width: 100px; background: yellow">a</div>b
1) the a and b will stick together for the first line, so span doesn't
honor the "width: 100px"
Read the spec,
http://www.w3.org/TR/CSS21/visudet.html#propdef-width

Width specifically does not apply to [non-replaced] inline elements. Span is
an inline element.

If a browser "honors" width for an inline element then that browser is
broken.
2) the div honors the "width: 100px", as the background is shown
yellow.
Yes. Div is a block element and so width will apply to it.
but it will force a line break both before the div and after
the div.
Yes, that is what block level elements do.

--
Richard.
>

Oct 26 '07 #2

P: n/a
On Oct 25, 5:17 pm, "rf" <r...@invalid.comwrote:
"Summercool" <Summercooln...@gmail.comwrote in message

news:11**********************@k35g2000prh.googlegr oups.com...
wow... i didn't know that, for
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<span style="width: 100px; background: yellow">a</span>b
<div style="width: 100px; background: yellow">a</div>b
1) the a and b will stick together for the first line, so span doesn't
honor the "width: 100px"

Read the spec,http://www.w3.org/TR/CSS21/visudet.html#propdef-width

Width specifically does not apply to [non-replaced] inline elements. Span is
an inline element.

If a browser "honors" width for an inline element then that browser is

IE 7.0 is honoring span width 100px, so IE 7.0 is broken? (both
quick mode or non-quirk mode).

by the way, how can i have an inline element (go with natural flow),
but has a width of 100px?

using div with display: inline won't work.

Oct 26 '07 #3

P: n/a
rf

"Summercool" <Su************@gmail.comwrote in message
news:11**********************@v23g2000prn.googlegr oups.com...
On Oct 25, 5:17 pm, "rf" <r...@invalid.comwrote:
>"Summercool" <Summercooln...@gmail.comwrote in message

news:11**********************@k35g2000prh.googleg roups.com...
wow... i didn't know that, for
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<span style="width: 100px; background: yellow">a</span>b
<div style="width: 100px; background: yellow">a</div>b
1) the a and b will stick together for the first line, so span doesn't
honor the "width: 100px"

Read the spec,http://www.w3.org/TR/CSS21/visudet.html#propdef-width

Width specifically does not apply to [non-replaced] inline elements. Span
is
an inline element.

If a browser "honors" width for an inline element then that browser is


IE 7.0 is honoring span width 100px, so IE 7.0 is broken? (both
quick mode or non-quirk mode).
IE6 and IE7 in standards mode conform to the specifications. The width is
ignored.

IE6 and IE7 in quirks mode honour the width so are broken. Given that qurks
mode was invented so as to be compatible with the very broken IE5.x this is
not surprising.

Your postings contain two examples. One puts the browser into quirks the
other into standards mode. Which one are you testing with? In general you
should be always using standards mode, and strict at that.
by the way, how can i have an inline element (go with natural flow),
but has a width of 100px?
You can't. Inline elements have no width attribute. Think about it. Inline
elements are flowed into line boxes. Flowed. What does width mean when the
elements are flowed? Read that section of the specs again.
using div with display: inline won't work.
Correct, because a div with display: inline is an inline element.

What is it you are trying to achieve. It is very possible that you are
solving the wrong problem.

--
Richard.
Oct 26 '07 #4

P: n/a
On Oct 25, 7:24 pm, "rf" <r...@invalid.comwrote:
"Summercool" <Summercooln...@gmail.comwrote in message

news:11**********************@v23g2000prn.googlegr oups.com...
On Oct 25, 5:17 pm, "rf" <r...@invalid.comwrote:
"Summercool" <Summercooln...@gmail.comwrote in message
>news:11**********************@k35g2000prh.googleg roups.com...
wow... i didn't know that, for
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<span style="width: 100px; background: yellow">a</span>b
<div style="width: 100px; background: yellow">a</div>b
1) the a and b will stick together for the first line, so span doesn't
honor the "width: 100px"
Read the spec,http://www.w3.org/TR/CSS21/visudet.html#propdef-width
Width specifically does not apply to [non-replaced] inline elements. Span
is
an inline element.
If a browser "honors" width for an inline element then that browser is
IE 7.0 is honoring span width 100px, so IE 7.0 is broken? (both
quick mode or non-quirk mode).

IE6 and IE7 in standards mode conform to the specifications. The width is
ignored.

IE6 and IE7 in quirks mode honour the width so are broken. Given that qurks
mode was invented so as to be compatible with the very broken IE5.x this is
not surprising.

Your postings contain two examples. One puts the browser into quirks the
other into standards mode. Which one are you testing with? In general you
should be always using standards mode, and strict at that.
by the way, how can i have an inline element (go with natural flow),
but has a width of 100px?

You can't. Inline elements have no width attribute. Think about it. Inline
elements are flowed into line boxes. Flowed. What does width mean when the
elements are flowed? Read that section of the specs again.
using div with display: inline won't work.

Correct, because a div with display: inline is an inline element.

What is it you are trying to achieve. It is very possible that you are
solving the wrong problem.
are you sure IE 7.0 will not honor the span's widht? because the
script above, IE 7.0 is honoring the span width for the first line.

now... can it still make sense to have inline element and specify the
width, for example, if i have an inline image of 60 px, and i want to
make it a width of 100px? i think i can use margin-left and right for
20px, but can't i use width -- just think of copying the 60px wide
image and pasting it into a newly-created image of 100px width.

the problem i am trying to solve is... without using table, i was
thinking of just arranging several 100px width and height boxes in one
row, and each containing a 75 x 75 image inside...

i suppose i can use float, with div
or span, with margins
or table

just that span with width won't work.

Oct 26 '07 #5

P: n/a
On 2007-10-26, Summercool <Su************@gmail.comwrote:
[...]
are you sure IE 7.0 will not honor the span's widht?
One can never be sure what IE 7.0 will do. The only thing one can say
with certainty is that it _should_ not honour the span's width.
>because the
script above, IE 7.0 is honoring the span width for the first line.

now... can it still make sense to have inline element and specify the
width, for example, if i have an inline image of 60 px, and i want to
make it a width of 100px?
Yes you can set the width of an image because it's a "replaced" inline
element. I believe rf already said this.
i think i can use margin-left and right for
20px, but can't i use width
Yes you can use margins (although there may limits on negative margins),
but you cannot use width.
the problem i am trying to solve is... without using table, i was
thinking of just arranging several 100px width and height boxes in one
row, and each containing a 75 x 75 image inside...
What you want is display: inline-block. But it isn't supported in the
current version of Firefox. It may however work in IE7 if you set widths
explicitly on the inline-blocks, which it sounds like you are planning
to do.
i suppose i can use float, with div
or span, with margins
or table

just that span with width won't work.
Most people use float as you suggest.
Oct 26 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.