Newbie Newbie - 5 months ago 18
CSS Question

CSS Sentence Case

Is there any way to format a "SENTENCE CASE"? e.g. "THIS IS SENTENCE 1. THIS IS SENTENCE 2. THIS IS SENTENCE 3. change to -> This is sentence 1. This is sentence 2. This is sentence 3.

Answer

CSS can convert first letter of each word, but not first letter of each sentence. Probably you need to use Javascript here:

<html>
  <head>
    <script language="javascript">
<!--
function fixCapitalsText (text)
{
  result = "";

  sentenceStart = true;
  for (i = 0; i < text.length; i++)
  {
    ch = text.charAt (i);

    if (sentenceStart && ch.match (/^\S$/))
    {
      ch = ch.toUpperCase ();
      sentenceStart = false;
    }
    else
    {
      ch = ch.toLowerCase ();
    }

    if (ch.match (/^[.!?]$/))
    {
      sentenceStart = true;
    }

    result += ch;
  }

  return result;
}

function fixCapitalsNode (node)
{
  if (node.nodeType == 3 || node.nodeType == 4) // Text or CDATA
  {
    node.textContent = fixCapitalsText (node.textContent);
  }

  if (node.nodeType == 1)
    for (i = 0; i < node.childNodes.length; i++)
      fixCapitalsNode (node.childNodes.item (i));
}
// -->
    </script>
  </head>
  <body onload="fixCapitalsNode (document.body);">
    THIS IS FIRST SENTENCE.
    THIS IS SECOND SENTENCE.
    This Is Third Sentence.
  </body>
<html>