Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First letter Capitalize and other letters in lower case in css?

Tags:

text

css

<p>THIS IS SOMETEXT</p>

I want to make it look like This is sometext which the first letter of the paragraph is uppercase.
Is it possible in CSS?

Edit: All my text is in capital letters.

like image 306
user2736812 Avatar asked Mar 21 '14 18:03

user2736812


People also ask

How do you make the first letter capital and other small in CSS?

Text-Transform Values lowercase makes all of the letters in the selected text lowercase. uppercase makes all of the letters in the selected text uppercase. capitalize capitalizes the first letter of each word in the selected text. none leaves the text's case and capitalization exactly as it was entered.

How do you make the first letter of each word capital in CSS?

The text-transform CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.

How do I convert a string to lowercase except first letter?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.

How do you make each word in a text start with a capital letter?

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.


3 Answers

You could use text-transform in order to make each word of a paragraph capitalized, as follows:

p { text-transform: capitalize; }

It's supported in IE4+. Example Here.

16.5 Capitalization: the 'text-transform' property

This property controls capitalization effects of an element's text.

capitalize Puts the first character of each word in uppercase; other characters are unaffected.


Making each word of an uppercase text, capitalized:

The following was under this assumption:

I want to make it look like: This Is Sometext

You have to wrap each word by a wrapper element like <span> and use :first-letter pseudo element in order to transform the first letter of each word:

<p>
  <span>THIS</span> <span>IS</span> <span>SOMETEXT</span>
</p>
p { text-transform: lowercase; }    /* Make all letters lowercase */
p > span { display: inline-block; } /* :first-letter is applicable to blocks */

p > span:first-letter {
  text-transform: uppercase;        /* Make the first letters uppercase      */
}

Example Here.

Alternatively, you could use JavaScript to wrap each word by a <span> element:

var words = $("p").text().split(" ");
$("p").empty();

$.each(words, function(i, v) {
    $("p").append($("<span>").text(v)).append(" ");
});

Example Here.


Making the first letter of an uppercase text, capitalized:

This seems to be what you are really looking for, that's pretty simple, all you need to do is making all words lowercase and then transforming the first letter of the paragraph to uppercase:

p { text-transform: lowercase; }

p:first-letter {
  text-transform: uppercase;
}

Example Here.

like image 152
Hashem Qolami Avatar answered Nov 14 '22 06:11

Hashem Qolami


Try This :

p {
  text-transform: lowercase;
}

p:first-letter {
  text-transform: uppercase;
}

Note

The parent of the text need to have the style block or inline-block or it wont work.

like image 20
Subeesh Avatar answered Nov 14 '22 06:11

Subeesh


I figured it out

p {
    text-transform: lowercase;
}

p:first-letter {
    text-transform: uppercase;
}
like image 39
user2736812 Avatar answered Nov 14 '22 07:11

user2736812