Html CSS 句子案例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14931117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS Sentence Case
提问by Lian
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.
有没有办法格式化“SENTENCE CASE”?例如“这是第 1 句。这是第 2 句。这是第 3 句。更改为 -> 这是第 1 句。这是第 2 句。这是第 3 句。
回答by iamshahid
you can use id/class:first-letter
property to achieve that
您可以使用id/class:first-letter
财产来实现这一目标
回答by Muhammad Talha Akbar
There are only three CSS properties.
只有三个 CSS 属性。
text-transform: capitalize;
text-transform: lowercase;
text-transform: uppercase;
None of them is gonna output as you want. You can use lowercase text-transform and them use JavaScript to capitalize first word of each sentence.
他们都不会像你想要的那样输出。您可以使用小写文本转换,它们使用 JavaScript 将每个句子的第一个单词大写。
回答by Mikhail Vladimirov
CSS can convert first letter of each word, but not first letter of each sentence. Probably you need to use Javascript here:
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>
回答by dinodsaurus
You could use css text-transform:capitalize;
property
您可以使用 csstext-transform:capitalize;
属性