Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalize first letter of sentences CSS

I want to capitalize the first letter of sentences, and also the first letter after commas if possible. I want to add the code in here:

.qcont {     width: 550px;     height: auto;     float: right;     overflow: hidden;     position: relative; } 
like image 863
1907 Avatar asked Jun 20 '12 23:06

1907


People also ask

How do you capitalize the first letter of a sentence in CSS?

You can capitalize the first letter of the . qcont element by using the pseudo-element :first-letter . This is the closest you're gonna get using only css. You could use javascript (in combination with jQuery) to wrap each letter which comes after a period (or comma, like you wish) in a span .

How do you capitalize the first letter of a sentence?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do I make uppercase letters in CSS?

You can achieve CSS all caps by using the keyword “capitalize.” In addition, text-transform capitalize converts all the first letters in all words to uppercase. Other values you can use with text-transform include “none,” “lowercase,” “full-width,” and “full-size-kana.”

How do I make the first letter of a paragraph big in CSS?

The ::first-letter selector is used to add a style to the first letter of the specified selector.


2 Answers

You can capitalize the first letter of the .qcont element by using the pseudo-element :first-letter.

.qcont:first-letter{   text-transform: capitalize } 

This is the closest you're gonna get using only css. You could use javascript (in combination with jQuery) to wrap each letter which comes after a period (or comma, like you wish) in a span. You could add the same css as above to that span. Or do it in javascript all together.

Here's a snippet for the css approach:

.qcont:first-letter {    text-transform: capitalize  }
<p class="qcont">word, another word</p>
like image 110
Luuuud Avatar answered Sep 18 '22 22:09

Luuuud


This cannot be done in CSS. The text-transform property makes no distinction according to the placement of a word inside the content, and there is no pseudo-element for selecting the first word of a sentence. You would need to have real elements, in markup, for each sentence. But if you can do that, then you could probably just as well change the initial letters to uppercase in the content proper.

Capitalization at the start of a sentence is a matter of orthography and should be done when generating the content, not with optional stylistic suggestions (CSS) or with client-side scripting. The process of recognizing sentence boundaries is far from trivial and cannot in general be performed automatically without complex syntactic and semantic analysis (e.g., an abbreviation ending with a period may appear inside a sentence or at the end of a sentence).

like image 23
Jukka K. Korpela Avatar answered Sep 18 '22 22:09

Jukka K. Korpela