Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capitalize first letter with JSTL/CSS?

Tags:

css

jsp

jstl

I am coding a JSP/JSTL application. I would like to style a link with the first letter uppercase and the rest lowercase. For example "my LINK" would become "My Link".

I saw that in CSS I can do:

<a href="..." style="text-transform: capitalize">${linkName}</a>

Which works only when ${linkName} is all lower case, but doesn't work as I want when is uppercase for instance if it contains "MY LINK" will be still displayed all uppercase.

I was wondering what is the best way to solve this problem, for instance it could be to use JSTL to convert ${linkName} to lower case.

Anyone knows how to do that? Or any alternative way?

Thanks in advance!

like image 375
stivlo Avatar asked May 05 '11 11:05

stivlo


People also ask

Can the text be Capitalised using CSS?

The text-transform CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized. It also can help improve legibility for ruby.

How do you capitalize the first letter of a sentence in HTML?

You can capitalize the first letter of the . qcont element by using the pseudo-element :first-letter . 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 .

How do you make all uppercase in CSS?

You can achieve CSS all caps by using the keyword “capitalize.” In addition, text-transform capitalize converts all the first letters in all words to uppercase. Other values you can use with text-transform include “none,” “lowercase,” “full-width,” and “full-size-kana.”


1 Answers

You can use JSTL functions fn:toLowerCase() to lowercase a string.

So, this should do

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<a href="..." style="text-transform: capitalize">${fn:toLowerCase(linkName)}</a>
like image 199
BalusC Avatar answered Oct 11 '22 16:10

BalusC