![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
After noticing that IE 7 beta supports selectors like p+p, I started wondering how to achieve a simple rendering of paragraphs so that 1) there is no vertical spacing between paragraphs (i.e. the usual equivalent of an empty line is suppressed) 2) a paragraph has a suitable first-line indentation to indicate the start of a new paragraph 3) the first paragraph in a sequence of paragraphs has no first-line indentation, however. This is easy to achieve if we drop 3) or implement it in a clumsy way, using a class attribute for such paragraphs. But how to avoid such clumsyness? |
|
Of course we could use just p { margin: 0; } p+p { text-indent: 1.2em; } but this would not degrade gracefully on old browsers: they would render p elements with no spacing between them and with no first-line indent. The user would have great difficulties in seeing where a new paragraph starts. If we regard it as acceptable to drop 3) on old browsers such as IE 6 and older that do not support advanced selectors, I think we use the following: p { margin: 0; } p, p+p { text-indent: 1.2em; } *+p { text-indent: 0; } On IE 6, all paragraphs have a first-line indentation, whereas on more standards-conforming browsers, the additional rules suppress the indentation for any paragraph that is not immediately preceded by another paragraph. |
#3
| |||
| |||
|
|
It seems to me that in a conforming browser the first paragraph in the body or in a div wouldn't match *+p because * doesn't match a null element, so the indentation wouldn't be eliminated. |
#4
| |||
| |||
|
|
After noticing that IE 7 beta supports selectors like p+p, I started wondering how to achieve a simple rendering of paragraphs so that 1) there is no vertical spacing between paragraphs (i.e. the usual equivalent of an empty line is suppressed) 2) a paragraph has a suitable first-line indentation to indicate the start of a new paragraph 3) the first paragraph in a sequence of paragraphs has no first-line indentation, however. |
|
degrade gracefully on old browsers [that do not support adjacent selectors - st] |
#5
| |||
| |||
|
|
Assuming I correctly understood what you want, I'd probably go no further than something like this: P {margin-top: 1em; margin-bottom: 0} P+P {margin-top: 0; text-indent: 1.2em} |
|
Browsers that don't support adjacent selectors should then indicate new paragraphs by an 'empty line'. IMO this is more than good enough for IE6, |
|
but if you must, feed it an extra p {text-indent: 1.2em} through IE's single useful feature, conditional comments. That way you don't bother more--CSS-compliant browsers with unnecessary rules and you keep your CSS cleaner and thus easier to maintain. |
#6
| |||
| |||
|
|
Does IE7 have :first-child? |
|
p { margin: 0; } p, p+p { text-indent: 1.2em; } *+p { text-indent: 0; } - - It seems to me that in a conforming browser the first paragraph in the body or in a div wouldn't match *+p because * doesn't match a null element, so the indentation wouldn't be eliminated. |
#7
| |||
| |||
|
|
"Sander Tekelenburg" <user (AT) domain (DOT) invalid> wrote: 41971A.04123216052006 (AT) textnews (DOT) euro.net... Assuming I correctly understood what you want, I'd probably go no further than something like this: P {margin-top: 1em; margin-bottom: 0} P+P {margin-top: 0; text-indent: 1.2em} That's one possible approach, but it doesn't quite achieve the desired rendering even on conforming browsers. I don't want to have an empty line before a paragraph. Such spacing is one of the basic typographic flaws in the default rendering in web browsers. Browsers that don't support adjacent selectors should then indicate new paragraphs by an 'empty line'. IMO this is more than good enough for IE6, Perhaps it's better than enough for IE 6, but what about the billion or so users of IE 6? If there's a relatively _simple_ way to achieve the desired rendering of paragraphs, I'd prefer using it even though it's a bit more complicated than needed for conforming browsers. but if you must, feed it an extra p {text-indent: 1.2em} through IE's single useful feature, conditional comments. That way you don't bother more--CSS-compliant browsers with unnecessary rules and you keep your CSS cleaner and thus easier to maintain. I'm afraid the "conditional comments" hack doesn't help keeping CSS code cleaner. |
#8
| ||||
| ||||
|
|
"Sander Tekelenburg" <user (AT) domain (DOT) invalid> wrote: 41971A.04123216052006 (AT) textnews (DOT) euro.net... Assuming I correctly understood what you want, I'd probably go no further than something like this: P {margin-top: 1em; margin-bottom: 0} P+P {margin-top: 0; text-indent: 1.2em} [...] I don't want to have an empty line before a paragraph. |
|
[...] Whether vertical spacing is needed depends on the _preceding_ element, not on the paragraph. In particular, by typographic rules, there should be no big gap between a heading and the first paragraph under it, since the heading as a heading _for_ the text that follows. |
|
[...] IMO this is more than good enough for IE6, Perhaps it's better than enough for IE 6, but what about the billion or so users of IE 6? |
|
I'm afraid the "conditional comments" hack doesn't help keeping CSS code cleaner. But perhaps more importantly, how would that help here? Since IE 6 does not support adjacent selectors, I would still be in square 1, wondering how to differentiate between "starting paragraphs" (i.e., <p> element not immediately preceded by a <p> element) and "continuation paragraphs". |
![]() |
| Thread Tools | |
| Display Modes | |
| |