admin管理员组文章数量:1422560
I am getting some external html page where all the data is ing in lowercase. with css, i tried to capitalize the first intial of the plete label tag but i am unable to do it, it makes plete uppercase like this:
.fontmodal {
text-transform:capitalize !important;
}
but that did not worked...
<table><fieldset><div><label>DATA</label></div></fieldset></table>
- This is the current Structure
Now i am trying to same in jquery, i am not sure what and how to proceed.
Here is my code what i am trying:
$('#Container2').find("table>label").css(textTransform,'capitalize');
I am getting some external html page where all the data is ing in lowercase. with css, i tried to capitalize the first intial of the plete label tag but i am unable to do it, it makes plete uppercase like this:
.fontmodal {
text-transform:capitalize !important;
}
but that did not worked...
<table><fieldset><div><label>DATA</label></div></fieldset></table>
- This is the current Structure
Now i am trying to same in jquery, i am not sure what and how to proceed.
Here is my code what i am trying:
$('#Container2').find("table>label").css(textTransform,'capitalize');
Share
Improve this question
edited Dec 16, 2014 at 13:35
SW4
71.3k20 gold badges136 silver badges139 bronze badges
asked Dec 16, 2014 at 13:19
user4360747user4360747
11
- text transform.. uppercase.. – Pogrindis Commented Dec 16, 2014 at 13:20
- @Pogrindis It's capitalize for the first letter, uppercase is the whole text – Mathew Thompson Commented Dec 16, 2014 at 13:20
- 1 Your HTML doesn't show any element with the fontmodal class. Could you write a fiddle ? – Denys Séguret Commented Dec 16, 2014 at 13:22
- 2 The question is misleading. You say that the data is ing in lowercase but the posted code says something different. – Hashem Qolami Commented Dec 16, 2014 at 13:30
- 1 You have not corrected the question, and your markup is invalid. The actual markup is relevant, since it affects the suitability of different approaches. And you should not confuse the issue by referring to jQuery when this is apparently a matter of HTML and CSS only (and once solved, trivial to implement in jQuery if needed). – Jukka K. Korpela Commented Dec 16, 2014 at 13:46
5 Answers
Reset to default 5See below:
label {
text-transform: lowercase;
}
div::first-letter {
text-transform: uppercase;
}
<table>
<fieldset>
<div>
<label>DATA</label>
</div>
</fieldset>
</table>
If you can't change the HTML and need to apply the capital letter on the first letter, you need to change the default display property of the <label>
tag :
:first-letter :
has only an effect on elements with a display value of block, inline-block, table-cell, list-item or table-caption. In all other cases, ::first-letter has no effect. (source MDN)
label {
display: inline-block;
text-transform: lowercase;
}
label::first-letter {
text-transform: capitalize;
}
<table>
<fieldset>
<div>
<label>DATA</label>
</div>
</fieldset>
</table>
You simplify it and do something like below.
$(document ).ready(function() {
$("label").addClass("capitalizer"); // Adjust specificity as needed
});
.capitalizer {
font-weight: bold;
font-size: 72px;
display: inline-block;
color: red;
}
.capitalizer::first-letter {
text-transform: capitalize;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<label>data</label>
</div>
Note: I prefer .addClass because .CSS adds inline css to your HTML and that's not advisable.
You can achieve this using the CSSS selector :first-letter
.
The subtly I have found is that it doesn't appear to be supported on the <label/>
tag (didn't work in my demo code, anyhow)
But we can get round that:
label {
text-transform: lowercase;
}
div:first-child:first-letter {
text-transform: uppercase;
color: red;
}
DEMO: http://jsfiddle/30trmm3w/1
I don't get what's wrong a simple CSS rule should do the trick :
#Container2 label {
text-transform: capitalize;
}
本文标签: javascriptCapitalizing the first letter of a label elementStack Overflow
版权声明:本文标题:javascript - Capitalizing the first letter of a label element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745328711a2653711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论