This question already has answers here:
CSS text-transform capitalize on all caps
(15 answers)
Transform ALL CAPS to Proper Case using CSS and jQuery
(2 answers)
Closed 4 years ago.
By definition, text-transform: capitalize capitalizes the first letter of each word in the selected text. But it only works for the lowercase text. My text is all uppercase, how can I use css text-transform to make the first letter uppercase and other letters lowercase?
::first-letter can be used to select the first letter from the first line of block-level elements.
p {
text-transform: lowercase;
}
p::first-letter {
color: red;
text-transform: capitalize;
}
<p class="capitalize">lowercase</p>
<p class="capitalize">UPPERCASE</p>
Related
I need to change size, color, and weight of every first letter of each word. I am not talking about Capitalize each first letter. I mean that target first letter and apply style according to my choice.
: Click Here to see example about which i am talking.
You should wrap every single word with a tag and use ::first-letter CSS selector .
Also, note that this selector does not work on inline elements. If you want to use it with an inline element, such a <span>, make sure you set display:inline-block (see here for more details: https://stackoverflow.com/a/7631782/11298742)
example :
p span { display: inline-block; font-family: 'Roboto', sans-serif }
p span::first-letter {
color: red;
font-weight: bold;
}
<p><span>Lorem</span> <span>ipsum</span> <span>dolor</span> <span>sit</span> <span>amet</span></p>
This question already has answers here:
What does a space mean in a CSS selector? i.e. What is the difference between .classA.classB and .classA .classB? [duplicate]
(3 answers)
Closed 6 years ago.
What's the difference between p ::first-letter and p::first-letter?
p::first-letter can successfully select the first letter inside a paragraph, but p ::first-letter cannot.
The selector p::first-letter selects the first letter inside the p whereas the p ::first-letter selects the first letter within the child elements of the p.
p ::first-letter is equivalent to p *::first-letter. The below is what the specs say:
If a universal selector represented by * (i.e. without a namespace prefix) is not the only component of a sequence of simple selectors selectors or is immediately followed by a pseudo-element, then the * may be omitted and the universal selector's presence implied.
Note: Even though the selector (p ::first-letter) itself points to the first letter inside all child elements, the ::first-letter selector works only on block or inline-block elements and hence wouldn't work on a span unless its display is modified.
p ::first-letter {
color: red;
}
p::first-letter {
color: blue;
}
span{
display: inline-block;
}
<p>Some text <span>inside a span</span> and <span>inside this span too</span>
</p>
p ::first-letter means change the style of the first letter of any element which is a descendant of p. Whereas p::first-letter means change the first letter of the p element.
I am trying to capitalize the first letter of each word. I did search for it but i did not get it, is it possible in CSS?
My Code currently works for the first letter only.
HTML
<span>Some Text Value</span>
CSS
.listing-table table th:first-letter
{
font-size: 15px;
font-weight: bold;
}
You can try to use this:
p { text-transform: capitalize; }
From the docs:
text-transform
This property controls capitalization effects of an element's text.
capitalize Puts the first character of each word in uppercase; other
characters are unaffected.
There is no way of doing this with CSS alone if the text in the element is in ALL CAPS already, the capitalize style will not work as it only changes the case to uppercase.
example:
p {
text-transform: capitalize;
}
<p>some text</p>
<p>Some text</p>
<p>SOME TEXT</p>
<p>sOME tExt</p>
If the entire text is already in lowercase, you can style it with the element{ text-transform: capitalize; }, but if elements are already in uppercase, the text-transform: capitalize; will not accomplish a "title caps". You will need to insert a javascript element.toLowerCase(); on the element in question then have CSS work its magic.
However, looking at the code provided and your question, the text is already doing what you want and the css selectors don't match the element so I'm not entirely certain what you are trying to accomplish.
The :first-letter pseudo-element targets the first letter of your element, not the first letter of each word. Besides, you're wrappring your code in a span in HTML and targetting a th in CSS, is it supposed to be like that?
Try using this instead :
.listing-table table th{
text-transform: capitalize;
}
Documentation of text-transform
For Bootstrap 5.1.3:
<div class="text-capitalize">
aoisdj oaisjd jmansdkajn
</div>
This question already has answers here:
Change last letter color
(8 answers)
Closed 8 years ago.
Is there a way to style just the last letter in CSS?
I know that for the first letter I can use:
p::first-letter {
color: red;
}
But how to style the last letter?
There is no last-letter selector instead wrap it in span and style it
p::first-letter, p span {
color: red;
}
<p>test test tes<span>t</span></p>
This question already has answers here:
Is it possible to exclude all css styling for one specific div container?
(2 answers)
Closed 8 years ago.
I have defined a style for input elements in HTML,
e.g.
input { font-family: Cambria; font-size: 13pt; }
So it by default applies to all the input elements I write in the page.
Now I want one specific input element with no style; can I do that?
The element selector has a lower priority than the class selector, so you can just add a class:
.special-input { font-family: sans-serif; font-size: 10pt; }