Html uppercase letters. How to make all capital letters in css. Let's transform the text
Often in a hurry when adding materials to the site or, for example, creating a new topic on the forum, the user can start writing a sentence (title) with a small (lowercase) letter. This is to some extent a mistake.
I'll show you several options for solving this problem: PHP and CSS are more suitable for already published materials, when how jQuery can fix the situation even before publication.
The first letter of a string is uppercase in PHP
In PHP there is a function called “ ucfirst", Which just converts the first character of the string to uppercase, but its minus is that it does not quite work correctly with Cyrillic.
For this, we will write our own small function. The implementation will look like this:
In this version, we will receive a sentence that begins with a capital letter, which, in fact, is what we need.
Uppercase first letter of string in CSS
This method visually (that is, in the source code of the site, the offers will appear as is) also converts the first character to uppercase.
Usage is as follows:
first sentence
second sentence
third sentence
fourth sentence
Using the pseudo-element " first-letter"And properties" text-transform»We have set the appearance for each first letter of the paragraph.
JQuery uppercase first letter of string
As I said earlier, this conversion method is best for materials that are yet to be published.
For example, we will take a text field (it will act as a field for entering a title for us) and write a small script for it that, when entering a sentence with a lowercase letter, makes it with a capitalization:
The script works both when writing text and simply pasting it. Do not forget that for the scripts to work on your site, you must have the jQuery library connected.
Controls the conversion of element text to uppercase or lowercase characters. When the value is other than none, the case of the source text will be changed.
brief information
Designations
Description | Example | |
---|---|---|
<тип> | Indicates the type of value. | <размер> |
A && B | The values \u200b\u200bmust be displayed in the order shown. | <размер> && <цвет> |
A | B | Indicates that only one of the suggested values \u200b\u200bshould be selected (A or B). | normal | small-caps |
A || B | Each value can be used alone or in conjunction with others in any order. | width || count |
Groups values. | [crop || cross] | |
* | Repeat zero or more times. | [,<время>]* |
+ | Repeat one or more times. | <число>+ |
? | The specified type, word or group is optional. | inset? |
(A, B) | Repeat at least A, but no more than B times. | <радиус>{1,4} |
# | Repeat one or more times, separated by commas. | <время># |
The values
capitalize The first character of each word in the sentence will be capitalized. The rest of the symbols do not change their appearance. lowercase All text characters become lowercase (lowercase). uppercase All text characters are uppercase (uppercase). none Does not change case.
Sandbox
Winnie the Pooh was always not averse to a little refreshment, especially at eleven o'clock in the morning, because at this time breakfast had long since ended, and dinner had not even thought to begin. And, of course, he was terribly happy to see Rabbit taking out cups and plates.
div (text-transform: capitalize;)
Example
Cultural monument of the Middle Ages
The Amazonian lowlands take on a small transport of cats and dogs, and Hayosh Bay is famous for its red wines.
The result of this example is shown in Fig. 1.
Figure: 1. Applying the text-transform property
Object Model
An object.style.textTransform
Specification
Each specification goes through several stages of approval.
- Recommendation - This specification is endorsed by the W3C and recommended as a standard.
- Candidate Recommendation ( Possible recommendation) - the group responsible for the standard is satisfied that it is in line with its objectives, but the help of the developer community is required to implement the standard.
- Proposed Recommendation ( Suggested recommendation) - At this point, the document is submitted to the W3C Advisory Council for final approval.
- Working Draft - A more mature version of the draft after discussion and revision for community review.
- Editor "s draft ( Editorial draft) - a draft version of the standard after editing by the project editors.
- Draft ( Draft specification) is the first draft of the standard.
Allows you to change the case of the letters of the text.
The default value is none, which has no effect on the text. The case of the text remains the same. The uppercase and lowercase values \u200b\u200bconvert characters to upper and lower case, respectively. If you specify a capitalize value, then only the first characters of each word will be capitalized. Inherit inherits the value from the parent.
Example
h3 (text-transform: uppercase;) .lowercase (text-transform: lowercase;) .capitalize (text-transform: capitalize;)This is the title. It has a text-transform property set to uppercase. All characters will be uppercase.
This paragraph has a Text-transform Property with a Value of Lowercase, which means all letters will be in lowercase.
And this last paragraph has a text-transform property with a CAPITALIZE property applied. The first letters of each word will be uppercase, and only that.