只有三个CSS属性.
text-transform: capitalize;
text-transform: lowercase;
text-transform: uppercase;
Run Code Online (Sandbox Code Playgroud)
他们都不会按你的意愿输出.您可以使用小写文本转换,并使用JavaScript来大写每个句子的第一个单词.
CSS可以转换每个单词的第一个字母,但不能转换每个单词的第一个字母.可能你需要在这里使用Javascript:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28921 次 |
| 最近记录: |