Lower case all then capitalize - pure CSS [duplicate] - capitalize

This question already has answers here:
First lowercase the text then capitalize it. Is it possible with CSS?
(4 answers)
Closed 8 years ago.
I saw this topic here: First lowercase the text then capitalize it. Is it possible with CSS?
But it wasn't pure CSS. I have a div that contains this text:
<div>
RaWr rAwR
</div>
I want to use css to make it look like "Rawr Rawr". Cut if I just to text-transform capitalize it makes it "RaWr RAwR", the already uppercase letters remain upper case. So I need to lower case it all first then capitalize, is the solution to wrap it in a div?
I tried wrapping it in another div but it didnt work:
<style>
#test3 { text-transform: lowercase; }
#test3 div { text-transform: capitalize; }
</style>
<div id="test3"><div>RaWr rAwR</div></div>

This should do it when you have the single words in different div's
#test3 { text-transform: lowercase; }
#test3::first-letter { text-transform: uppercase; }
<div id="test3">haLLo</div>

Sadly, you cannot do this with pure CSS. For now your best hope is to either rewrite text to avoid medial/final capitals or use JavaScript. (Yes, my eyes are rolling too.)
Your suggested approach doesn't work because only one text-transform property value applies to an element at a time. When you specify something like…
#parent { text-transform: lowercase; }
#parent #child { text-transform: capitalize; }
…the value of text-transform on the child element is now capitalize, and nothing else. This is the only transformation applied to that element.
There is a draft proposal to allow authors to define custom mapping tables with an #text-transform rule, but as it stands I doubt it would work for this scenario. The problem is that the scope descriptor (where in a word the transformation applies) only takes one value—you could define a transformation on the whole word or some combination of the start, end or middle parts of a word, but it's not obvious if you could have different transformations for each part.
This seems to be acknowledged in Issue 8 on the wiki draft proposal, and multiple transforms were discussed a couple of years back on www-style. In that thread it is suggested that only a single text-transform value should be allowed on an element, and that combining should be done in the #text-transform rule; however, the draft spec notes:
If the text-transforms referred to have a different scope than the scope specified
in the text-transform that refers to them, they apply at the intersection of the
two scopes.
So a rule like this wouldn't work:
#text-transform lowercase-then-capitalize {
transformation: lowercase, "a-z" to "A-Z" single;
scope: initial;
}
I can see three obvious solutions:
allow multiple scope values to be specified in the #text-transform rule;
add a descriptor to inherit a previous transformation without overriding its scope value; or
permit multiple text-transform values for a selector.
The www-style mailing list might be a good place to take this if you ever want to see a pure CSS solution to this question.

You are using nested div,
So #test3 { text-transform: lowercase; } is applied for Parent div so it applies for Both Parent and Child Divs
when you override the #test3 div { text-transform: capitalize; } to the Child Div the first style text-transform: lowercase; is ignored

Unfortunately, until CSS 3 there is no way to do this in pure CSS way, as per this document there are only 5 possible values to text-transform and none of them will solve this requirement!
But in future there might be provision for custom rule for text transform similar to Counter Sytle

Related

CSS Conditional h2 text [duplicate]

This question already has answers here:
Is there a CSS selector for elements containing certain text?
(20 answers)
Closed 7 years ago.
Is it possible to set a conditional for the h2 text of a class? the h2 does not have a unique class or id to it, and multiple h2's with a dynamic changing order. So i can't target say the 3rd h2 because its always shifting.
h2.arker.fun.header {
// some statement If h2 text = "Gamer" then set text-transform: lowercase
}
There was once proposed one pseudo class known as :contains to handle this situation. But they haven't added it yet in the current draft of CSS3.
However you may use some Javascript. For Example to deal with this problem
for (var i= document.links.length; i-->0;){
if (/\bSpecificWord\b/i.test(document.links[i].innerHTML)
document.links[i].style.color= 'red'; }
Hope you are not restrained from using Javascript.
As others (#Paulie_D, #Mia Marks, #YourFriend) have already pointed out, there is no CSS < 4 selector based on content and the closest you can get is the attribute selector.
Just a crazy idea:
h2.arker.fun.header:before {
content: attr(data-text);
}
h2.arker.fun.header[data-text="Gamer"] {
text-transform: lowercase;
}
<h2 class="arker fun header" data-text="Gamer"></h2>
don't do it at home...
u can add attribute in that h2 tag
and put the condition like:
h2[if='mytype']{text-transform:lowercase;}

Using data attributes instead of classes in CSS

HTML
<div data-foo> ... </div>
CSS
div[data-foo]{ ... }
Is this a good idea? Are there any drawbacks?
I think the data- approach makes sense when I have hundreds of "foo" elements, because the HTML markup size decreases (-3 characters for each element).
div[data-foo] is not supported in old IE (IE6, see here: http://www.quirksmode.org/css/selectors/)
div[data-foo] makes less semantic sense
class="foo" and data-foo will take up about the same space when DEFLATE-d. If you haven't set up your server to deflate, you should.
class=foo is only one character longer than data-foo even uncompressed, and is perfectly valid HTML.
It totally depends on you, for example elements must be having different attributes, so you need to define styles and even repeat some, instead I'll use a class which I can use for both, instead of using attribute selector which will limit my declared properties upto an element with that attribute, where you can freely use classes regardless of element attribute combination
.class { /* You can use this anywhere you need these properties */
font-family: Arial;
font-size: 13px;
}
Where as this will limit to ELEMENT-ATTRIBUTE combination
div[data-menu] { /* This will LIMIT you to a combination of div
element having an attribute called data-menu */
font-family: Arial;
font-size: 13px;
}
Important : Specificity will make you a huge mess

How to capitalize first line with CSS? ::first-line pseudo-element not working

Right now I've got a paragraph and I'd like to capitalize the entire first line. I've set the first paragraph to an ID "firstp" and tried:
#firstp::first-line {
text-transform: uppercase;
}
I've tried it with text-transform: capitalize but that doesn't work either. It's strange because I've managed to change the first letter (changed font size) using #firstp:first-letter.
text-transform on :first-line is really buggy right now, see the reference here http://reference.sitepoint.com/css/text-transform
You can use this jquery plugin called linify https://github.com/octopi/Linify to select the first line and then apply the property of text-transform: uppercase
Regards,
I think Chrome has a problem with ":first-line". Try removing that and using james31rock's syntax on this page, except in his example the CSS should be "#firstp{..." to reflect the ID in his HTML rather than ".makeupper".
You might want to use:
font-variant: small-caps;
It looks better in my opinion and is supported in all major browsers.
More info
http://en.wikipedia.org/wiki/Small_caps
In order to accomplish this you must use the following Pseudo-element within the correct syntax. Example:
HTML PORTION:
<selection id="Welcome">
<p>Some text</p>
</section>
CSS SHEET:
#Welcome p:first-of-type:first-line {
text-transform: uppercase;
}
I hope this helps. Sorry for the late entry. I guess, better late than never!
There might be another way ...
What if you have two spans with text inside paragraph, one of the spans would have position set to upper left corner of the paragraph, so the two spans would overlap. Now set height of the upper span to about line-height of your text and overflow to hidden so only first line of the span would be visible. Set text-transform to uppercase on the upper span and vou la you have first line in uppercase.
Downside of this solution is, uppercase text is wider so there might be missing words on next line. You can fix this by using fixed-width font or try to set letter-spacing on both spans so width of uppercase and lowercase texts would be same.
Here is jsFiddle, though it's not ideal sometimes when you change the window size, it might be sufficient.
It doesnt seem to work either way, in Chrome. In I.e. text-transform works. I do not have firefox to test with.
http://jsfiddle.net/vJSeq/4/ - using text-decoration
http://jsfiddle.net/vJSeq/3/ - using text-transform
You can see that the selector is right because it is highlighted.
My suggestion would be to use something to seperate the text you want highlighted, by creating a span tag inside of the paragraph and assign it a class
<p id="firstp">to stop the degradation of the planet's natural environment and to build a future in <span class="makeupper">which humans live in harmony with nature, by; conserving</span> the world's biological diversity, ensuring that the use of renewable natural resources is sustainable, and promoting the reduction of pollution and wasteful consumption.</p>
​
and the css
.makeupper
{
text-transform: uppercase;
}
http://jsfiddle.net/vJSeq/5/

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;
}
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>
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).
If you need to capitalize the first letter in contenteditable container you can't use the css property
#myContentEditableDiv:first-letter {
text-transform: capitalize;
}
because when you try to delete a letter automatically you will delete all the text contained in the contenteditable.
Try instead the example provided by sakhunzai in https://stackoverflow.com/a/7242079/6411398
for a working solution.
text-transform:capitalize; will capitalize the first letter of a sentence, but if you want to also do it for commas you will have to write some javascript. I agree with #BoltClock, though. Why on earth would you want to capitalize after a comma?
Edit: For the sake of readers: text-transform:capitalize; will capitalize each word of a sentence, not the first one only.
You must use the :first-letter CSS selector with the above.

How do you read !important in CSS? [duplicate]

This question already has answers here:
What does !important mean in CSS?
(5 answers)
Closed 3 years ago.
How is the CSS attribute property !important read?
Is it really important, exclamation mark important, ...?
Answer: From the answers below, it seems to be read simply important, or bang important.
an "!important" declaration (the delimiter token "!" and keyword
"important" follow the declaration) takes precedence over a normal
declaration.
http://www.w3.org/TR/CSS2/cascade.html#important-rules
Basically, where two style rules are the same... it gives the one marked !important greater importance and will apply those styles.
Example
div{
opacity:0 !important;
}
div.jason{
opacity:1;
}
The first rule would be applied even though the second rule is more specific (one element + one class as opposed to one element)
Note: IE6 ignores !important when you have two of the same property and one of them is important - it'll always apply the last declaration, whether or not it was marked important. **Added from #BoltClock's comment below.
Warning: !important is a hammer that should only be used when absolutely necessary. Almost always, it is better to use more specific selectors to achieve greater specificity and have your styles applied the way you want. !important can make it very difficult for future developers to find and make changes to your code.
One good use case: !important is great for user-defined styles, where a user wants to manipulate Web site pages in specific way in his browser (say make all the backgrounds black and the text yellow). Without having to worry about specificity, the user can add styles to certain elements (like body) and make the styles render.
Just "important" or "bang important." The ! is definitely not a negation in this case.
It's not a tag, it's a keyword.
body { color: red !important; } means, in English, "The text-color of red is important".
In terms of how CSS sees it, it applies more "weight" to that declaration, so it will be (far) more likely to be the applied style.
For an example of this, we can use
p { color: red; }
p.blue { color: blue; }
Now, any p with a class of blue will show blue text, all the others will show red text.
If we change it to this...
p { color: red !important; }
p.blue { color: blue; }
They will all show red text (even if they have a class of blue), as we've given more important to the first selector.
I like to think of it as "NOT important".
p {
color: red !important; /* The rest is NOT important for this CSS property. */
}
Meaning that everything else from that declaration and on is NOT important and should not be taken into account. The idea came from the usage of the "!" character as a boolean NOT in many programming languages. This way the !important makes sense as you read it.
I guess I read the ! as "very".
p { color: red !important }
I read as "Paragraphs have the color red, which is very important.

Resources