Sentence case

B

BernieH

I need to display some incoming all-caps text in sentence case (first
letter of each word capitalised). I'm practising on the following code
snippet, but it just won't work. Any idea why?

TIA

BernieH

<html>
<head>
</head>
<body>
<span style="text-transform:lowercase; text-transform:capitalize;">
THIS IS UPPERCASE
</span>
</body>
</html>
 
B

brucie

In alt.html BernieH said:
I need to display some incoming all-caps text in sentence case (first
letter of each word capitalised).

the only practical way to do it is use the string functions of your
favorite server side language.
I'm practising on the following code
snippet, but it just won't work. Any idea why?
<span style="text-transform:lowercase; text-transform:capitalize;">
THIS IS UPPERCASE</span>

the above only works if the text is initially lowercase. also some
readers may ignore the css and spell out all caps words which would be
annoying.
 
M

Mitja

BernieH said:
I need to display some incoming all-caps text in sentence
<span style="text-transform:lowercase;
text-transform:capitalize;"> THIS IS UPPERCASE
</span>

text-transofrm is a _property_, so it can only have one value, they don't build up. What you end up with, therefore, is
text-transform:capitalize, which completely overrides your other text-transform rule before it.
And yes, capitalization only works for lowercase strings, unfortunately.
 
J

Jukka K. Korpela

brucie said:
the only practical way to do it is use the string functions of your
favorite server side language.

Or by something more elaborated. I'm afraid many string functions have no
idea of how many letters there really are. They may well fail to process
properly other bicameral scripts than the Latin script, and they might
even fail for all other letters but "a" through "z" without diacritics.

Of course, naive authors or programmers may assume that everyone uses
English and doesn't even write foreign names correctly. ;-)
 
S

Steve Pugh

I need to display some incoming all-caps text in sentence case (first
letter of each word capitalised).

That's not sentence case. Sentence case is where only the first letter
of the sentence and the first letter of proper nouns and I are
capitalised. What you're describing is title case where (almost[1])
every first letter is capitalised.

But that's beside the point...
I'm practising on the following code
snippet, but it just won't work. Any idea why?

<span style="text-transform:lowercase; text-transform:capitalize;">
THIS IS UPPERCASE
</span>

The text-transform property can only apply once to each element so in
this case the last declared property is applied, but because the text
is all upper case text-transform:capitalize; has no effect.

The closest you could get in CSS is something like this:

span {text-transform:lowercase;}
span b {font-weight: normal; text-transform:capitalize;}

<span><b>T</b>HIS <b> I</b>S <b>U</b>PPERCASE</span>

Obviously this is clunky and has disadvantages[2].
Better to either persuade whomever is supplying the text to supply it
in the format you want or to use the server side language of your
choice to transform the text before including it in your pages.

[1] Prepositions, conjunctions ands articles of less than five letters
length are not normally capitalised in title case, hence CSS
text-transform: capitalize; is only an approximation of title case.

[2] ISTR speech browsers that would split the word at a tag, so
<b>T</b>HIS would be read as "tee his". Anyone know if this is still
the case in the current generation?


Steve
 
M

Mark Parnell

The closest you could get in CSS is something like this:

span {text-transform:lowercase;}
span b {font-weight: normal; text-transform:capitalize;}

<span><b>T</b>HIS <b> I</b>S <b>U</b>PPERCASE</span>

For sentence case (not title case, as the OP is talking about), you
could use

span {text-transform:lowercase;}
span:first-letter {text-transform:capitalize;}

<span>THIS IS UPPERCASE</span>
 
S

Steve Pugh

Mark Parnell said:
For sentence case (not title case, as the OP is talking about), you
could use

span {text-transform:lowercase;}
span:first-letter {text-transform:capitalize;}

<span>THIS IS UPPERCASE</span>

True under CSS2.1 but under CSS 2 the :first-letter only applies to
the first letter of block level elements. Need to test to see what
browser support is like.

Steve
 
M

Mark Parnell

True under CSS2.1 but under CSS 2 the :first-letter only applies to
the first letter of block level elements. Need to test to see what
browser support is like.

Didn't realise that - thanks. Would be better as a paragraph in most
cases, anyway - I was just copying your example. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top