CSS Suggestion Case

Is there any way to format "CASE APP"? for example, "THIS IS PREVENTION 1. THIS IS PROVISION 2. THIS PROPOSAL 3. change to → This sentence 1. This sentence 2. This sentence 3.

+5
source share
4 answers

CSS can convert the first letter of each word, but not the first letter of each sentence. You probably 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>
+6
source

you can use property id/class:first-letterto achieve this

+9
source

CSS.

text-transform: capitalize;
text-transform: lowercase;
text-transform: uppercase;

, . , JavaScript .

Fiddle

+6

You can use the css property text-transform:capitalize;

-1
source

All Articles