How to give sentence case to sentences through CSS

2019-03-02 16:51发布

How to give sentence case to sentences through CSS or javascript?

I've tried these CSS properties but these are different

capitalize    Transforms the first character of each word to uppercase
uppercase   Transforms all characters to uppercase
lowercase   Transforms all characters to lowercase

Edit: 19 FEB 2010

is there any option in jquery to achieve this?

4条回答
放荡不羁爱自由
2楼-- · 2019-03-02 17:19

Don't use JavaScript to fix your content. This is inefficient on a scale of ridiculous. Write your content correctly before you publish it or use some coding scheme on the server side. If this is some scheme to fix content that you don't control, such as user supplied, then simply state the content comes from your users and not you.

Seriously, this is going to delay the loading of your page significantly and cause visitors to abandon your site.

查看更多
该账号已被封号
3楼-- · 2019-03-02 17:23

Something similar to this will work in JavaScript:

function sentenceCase(theText) {
    return theText.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});

}

Won't work perfectly in ALL cases, but, it might get you somewhere. There are a lot more elegant solutions on back-end languages, typically, though.

查看更多
Lonely孤独者°
4楼-- · 2019-03-02 17:31
p:first-letter{text-transform:capitalize}

Capitalizes the first word of each sentence

查看更多
Luminary・发光体
5楼-- · 2019-03-02 17:39

what about:

str = "HeLlo Its aamiR here";
str = str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase()
查看更多
登录 后发表回答