Shubhankar Shubhankar - 4 months ago 69
CSS Question

How to change the label color of the textfield in Struts 2

I am stuck in changing the font color of

<s:textfield name="name" key="user.name"/>


Here
user.name=User
comes from resource bundle. So in JSP HTML page, it displays
User Name
label and a textfield, but I want to change the font of
User Name
label.

Answer

You can do this with CSS attribute selector. Give your <s:textfield> an id and reference this id in CSS like that:

<style type="text/css">
  label[for="nameFieldId"] {
    color: red;
  }
</style>

<s:textfield id="nameFieldId" name="name" key="user.name"/>

This will work because xhtml theme generates <label> for <s:textfield> tag with for attribute.

Comments