|
|
Subject:
Dirt simple CSS question
Category: Computers Asked by: hapgood-ga List Price: $2.50 |
Posted:
10 Nov 2006 13:37 PST
Expires: 10 Dec 2006 13:37 PST Question ID: 781718 |
This is really embarrassing but I can't figure out how to use the CSS command 'width'. I want to be able to use it in the context of an embedded command, as follows. Imagine I write: "<span style="width:25px">The fox jumped over the lazy dog.</span>". Ideally that sentence would then appear formatted to a width of 25 (or whatever) pixels. The manuals and the online sites all make me think this should be possible. But nothing I do works. I'm beginning to wonder if "width" doesn't work as an embedded command. But surely that is wrong. | |
| |
| |
|
|
Subject:
Re: Dirt simple CSS question
Answered By: aht-ga on 12 Nov 2006 23:46 PST Rated: |
hapgood-ga: Thanks for the clarification. The reason why you are seeing the problem, is because the width property is specifically not applicable to inline elements... and the <span> tag is specifically used for grouping inline elements, so officially the width property is not applicable to spans. W3C: Block-level and inline elements http://www.w3.org/TR/html4/struct/global.html#edef-SPAN W3C: Visual formatting model details http://www.w3.org/TR/REC-CSS2/visudet.html#propdef-width So, if you are using Mozilla Firefox, or Opera, as your browser, then you will see the results that you are seeing. If, however, you are using Internet Explorer (at least versions 6 or 7, as far as I'm aware), then the width attribute does work with SPAN, because Microsoft chose to go beyond the W3C specifications: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/width_2.asp Interestingly, Microsoft refers to the CSS1 specification where the 'width' attribute is defined; yet, in that very specification, it specifies that 'width' only applies to block-level and replaced elements, not to inline elements such as SPAN. So, to answer your final question, the difference between P and SPAN, is that P is a block-level element, while SPAN is an inline element. Since 'width' only applies to block-level and replaced elements, a browser that strictly conforms to the W3C specifications (such as Firefox or Opera) will ignore the 'width' attribute within a SPAN tag, while a less-strict browser such as Internet Explorer, will let it work. Note that if your page design permits you to replace your SPAN tag with a properly-used DIV, then you can use the width attribute. Regards, aht-ga Google Answers Researcher |
hapgood-ga
rated this answer:
Clears up all my outstanding questions. Excellent answer. |
|
Subject:
Re: Dirt simple CSS question
From: adixm-ga on 10 Nov 2006 17:48 PST |
the following code is ok by ie and firefox.So,maybe you check you code. /***************************************************************************** <p>This is a paragraph <span style="color:#0000FF;">This is a paragraph</span> This is a paragraph</p> <p> <span style="color:#00DD45;width=25px"> This is another paragraph </span> </p> ******************************************************************************/ Hope you can resolve the problem. |
Subject:
Re: Dirt simple CSS question
From: jaybf-ga on 10 Nov 2006 21:20 PST |
from what you mentioned above it kinda sounds like you're expecting the style to set the width of the text and not the span. the style will apply to the width of the span not the text. the usage you showed is correct for setting the width of the span. if you want to change the width of the text that isn't an option i'm aware of. you can set the font size with the font-size: property. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |