Css capital letters. Creating capital letters using CSS. HTML letters and CSS spacing between them
CSS capital letters help break the monotony of the same type of design, the texts of which look the same from start to finish.
Initial letters then and now
Chroniclers used capital letters in handwritten manuscripts, some of them dating back to the 5th century. Capital letters continued to be used from the 8th to the 15th centuries, when printing presses allowed printing to be brought to an industrial level. Both handwritten and printed initial letters were placed at the beginning of the text. They were often decorated with a decorative pattern that was located around the letter.
Raised and dropped letters are still used today. They can be found in newspapers, magazines and books, as well as in digital printing. Raised type is sometimes called elongated type. They are placed flush with the bottom of the text that follows them. Dropped letters are placed flush with the top of the text, sometimes in a layer behind the body of the text content, or the rest of the text wraps around them.
Raised letters are much easier to define because they are flush with the rest of the text and usually don't need to change the wrap around the outer margins. Omitted letters require more fine-tuning. It will be easier for you to understand this if you first understand how raised characters are handled.
Using classes
Designers who already have an understanding of CSS know that they need to create a separate CSS class for the first capital letter.
The CSS code for the paragraph element and the class that creates the letter would look like this:
p (font-size:20px; font-family: Georgia, "Times New Roman", Times, serif;).myinitialcaps (font-size:48px; font-family: Didot;)
And the HTML code will look like this:
What gives us:
Seems too easy? You'll actually have to make adjustments depending on the specific letters raised, since each capital letter requires special kerning. After choosing a font for the raised letters and for the body text, you need to create separate classes for each raised letter. In the below css-class.myinitialcapsi the margin on the right is negative to reduce the distance between I and n.
Myinitialcapsi (font-size:48px; font-family: Didot; margin-right:-1px;)
n this case, there’s some extra space between the “I” and “n.”
including a new class with a negative margin pulls it closer.
Depending on the screen resolution in the example above, the I and n may look like they're blurred together. This is due to the serifs at the ends of the letters. So before you decide on your final CSS styles, test your site on different devices to see how CSS caps text looks on them.
Quotes and other special cases
You can enlarge not only the letters at the beginning of the text. You can implement another class to create a larger version of quotation marks that will appear next to the letter. In our case, neither a letter class with a size of 48 nor a text class of 20 pixels is suitable for quotation marks. Rather, it will be something in between - 30 pixels. We'll move the quotes down 4 pixels to optically align them with I:
Myinitialcapsq (font-size:30px; font-family: Didot; float:left; margin-top:4px;)
ncluding” a new class with a negative margin pulls it closer.
You need to be very careful about setting each of the CSS capitalizations along with the quotes so that their kerning and alignment matches the surrounding markup. For example, the letter T will need to be moved to the left, slightly beyond the edge of the paragraph, so that its transverse line visually fits into the layout. You will need to do the same with round letters, such as C, G, O and Q. This example uses font sizes of 20, 30, and 48. But you will need to select sizes based on the specific fonts you choose. As well as the sizes and resolutions of the screens on which the site will be viewed.
Pseudo-elements and pseudo-classes
Using the CSS pseudo-element, you can easily create a raised letter by adding ::first-letter to a paragraph element. Use :first-letter ( with one colon) for legacy browsers:
p ( font-size: 1.2em; font-family: Georgia, "Times New Roman", Times, serif; line-height:2em;padding-bottom:1.2em;) p::first-letter ( font-size: 3.6em; text-transform: uppercase; font-family: "Monotype Bernard Condensed", serif; margin-right:0.03em;).initialb (margin-right:-0.1em;).initialn (margin-right:-0.15 em;)
HTML code that contains CSS classes that take into account the kerning of the letters N and B would look like this...
An initial letter, with the first letter being a capital letter.
With a line break, the next line has no initial cap.
n otice in the HTML source how the first letter, not a capital letter in the HTML, gets sized to the initial cap size of 3.6em. Neat, huh?
B ut with a hard return, and a new paragraph started, another initial cap always gets created. You might be asking yourself, How am I going to account for this? Am I supposed to have an initial cap at the beginning of very new paragraph? Well, you could. But, do you want it to look that way, and does it absolutely have to look that way?
The first capital letter of the paragraph is converted to a letter.
The first letter after a line break will not be converted to capital.
O Note that in the HTML source code the first letter is not capitalized, but it is converted to a 3.6em character.
ABOUT However, even after a forced line break, and at the beginning of each new paragraph, a letter is always created. You may ask yourself: How should I take this into account? Do I need to add letters for all these cases? Well, you can. But is this necessary?
Even with the benefits that pseudo-elements provide, we had to add a lot of code to define separate classes to handle kerning and padding issues. But this method converts the first letter of each new paragraph to a CSS capital letter. For some, it may not be suitable because it does not need to transform the first letter of each paragraph.
Combining pseudo-classes and pseudo-elements to create a smart layout
Adding the :first-child pseudo-class helps solve the problem of unnecessary conversion of first letters:
p ( font-size: 1.2em; font-family: Georgia, "Times New Roman", Times, serif; line-height:2em;padding-bottom:0.5em;) p:first-child::first-letter ( font-size: 3.6em; text-transform: uppercase; font-family: "Monotype Bernard Condensed", serif; margin-right:0.03em;)
Combining this code with HTML:
The first letter that is defined as first-child is the only letter that is converted to a raised drop cap by this method.
Since only the letter defined as first-child is converted, note that this example is different from the previous one, without first-child. In addition, we do not convert the first letters after the beginning of a paragraph and after a forced line break. This looks more elegant than how the layout looked when we converted all the first letters of the paragraphs.
The advantage of using pseudo-classes is the ability to handle various special cases. What about the downsides? There are many different pseudo-classes, and they can be combined in so many ways that it can make your head spin. For example, the pseudo-classes :first-child and :first-of-type can produce the same results. You can also apply a pseudo-class not only to a paragraph, but also to elements section ( font-size: 1.2em; font-family: Georgia, "Times New Roman", Times, serif; line-height:3em;) section>p:first-child:first-letter ( font-size: 4em; text-transform: uppercase; font-family:Didot, serif; margin-right:5px;) And along with HTML: At the beginning of the section, a raised drop cap is specified for the first letter. And a new paragraph... If you're feeling experimental, you can explore different methods in addition to :first-child and :first-of-type . For example, such as :nth-of-type or :nth-of-child to see how these or other types of pseudo-classes can be used for CSS capitalization text. Whether you follow the principles outlined in this article or start digging deeper, once you learn how to work with the CSS pseudo-classes first-child , :first-of-type , and :first-letter , you'll be able to apply them correctly to HTML elements. Good day, site building geeks. Today's publication will discuss the topic of designing text content. That is why you will learn how to set capital letters using CSS tools, get acquainted with several options for creating a drop cap and, of course, you will be able to try everything out in practice. Well, now let's move on to the fun part! Thanks to cascading style sheets, you can change both the first character of a block and the entire text. I'll tell you how you can do both. Moreover, all the tools mentioned in this article are supported in three language levels: css1, css2, css2.1 and css3. I'll start with an interesting property that modifies all text content in the selected . This text-transform. The named element can convert characters to uppercase, lowercase, and also set each first character of a word to a capital letter. I wrote more about the values in the table. Now, to reinforce the theoretical material, look at an example.
The promotion is valid in all branches located in your city. If you don't know what the term "drop cap" means, then now is the time to find out, as it is directly related to the current topic. A capital letter (or sometimes they also say an initial) is the first letter of a chapter, which differs from the rest in its large size, color and, in some cases, even font design. In real life, an example of such a letter can be found in old manuscripts and books. There are several ways to create an initial. Often the symbol is highlighted with a markup language tag and then certain properties are prescribed in the styles that modify it. This is a good way, but this publication talks about CSS mechanisms (which, in my opinion, are much more logical and convenient to use in this case). To solve this problem, you can use a tool such as. So, in this case we use:first-letter. Like all pseudo-elements, it is assigned to a selector using a colon. After all the rules of style sheets, properties are indicated. However, you can only apply properties that relate to editing fonts, padding, color, background, margins, and borders. I propose to consider a specific example. When implementing the presented small program, I decided to make not just a colored initial letter, but fill it with flowers. To do this, you need to use a few tricky tricks by setting the font color to transparent and filling the letter with the selected image.
This paragraph contains a sentence with very interesting content. Let's continue the interesting story in the next paragraph. The resulting result looks very attractive and unusual, which is an ideal solution for. As you can see, this topic is very simple. You can easily use the program code I have provided for your web resources, modifying and customizing it to suit your style. If the material presented was useful to you, then subscribe to my blog updates and do not forget to share the knowledge you gain (and of course the link to my blog) with your friends. Good luck! Bye bye! Best regards, Roman Chueshov Allows you to change the case of text letters. The default value is set to none , which has no effect on the text. The case of the text remains the same. The uppercase and lowercase values convert characters to uppercase and lowercase, respectively. If you specify capitalize , only the first characters of each word will be capitalized. Inherit inherits the value of its parent. The Text-transform Property with the Value Lowercase is applied to this paragraph, which means all letters will be in lowercase. And to this last paragraph the text-transform property with the CAPITALIZE property is applied. The first letters of each word will be capitalized, and only those.Let's transform the text
Attention!
!Tomorrow there is a discount on all cosmetic products!
Creating a drop cap
Example
h3 ( text-transform: uppercase; ) .lowercase ( text-transform: lowercase; ) .capitalize ( text-transform: capitalize; )
This is the title. It has the text-transform property applied to it with the value uppercase. All characters will be uppercase.