label styling for single character

前端 未结 2 1952
南旧
南旧 2021-01-25 00:12

I need to change the color of one character in this label specifically the *.
This will need to be changed for several sections, but not changed for many others

相关标签:
2条回答
  • 2021-01-25 00:23

    By default Struts2 uses themes (XHTML by default) to generate common HTML MarkUp for the elements.

    As pointed out by @AleksandrM's comment, requiredLabel attribute would generate a span with the asterisk in it, that you can style with CSS.

    Be sure to give an id to elements by yourself, or Struts will generate an unique one by himself that would be difficult to handle (form name _ elementname plus a number or something like that).

    Then this

        <s:textfield id = "bankName" 
                   name = "bankName"
                  label = "Bank Name"
          requiredLabel = "true" />
    
        <s:textfield id = "bankAddress" 
                   name = "bankAddress" 
                  label = "Bank Address"
          requiredLabel = "true" />
    

    will generate the following HTML:

        <label for="bankName"><span>*</span>Bank Name</label>
        <input type="text" id="bankName" name="bankName" />
    
        <label for="bankAddress"><span>*</span>Bank Address</label>
        <input type="text" id="bankAddress" name="bankAddress" />
    

    that you can style easily with:

    <style>
    
        /* all "*" spans */
        label > span {
            color: silver;
        }
    
        /* differet style for bankName's "*" span */
        label[for=bankName] > span {
            color: red;
        }
    
        /* differet style for bankAddress's "*" span */
        label[for=bankAddress] > span {
            color: green;
        }
    
    </style>
    

    Running example

    0 讨论(0)
  • 2021-01-25 00:39

    You should be able to wrap the character in <span> tags and set the colour in CSS. I'm not familiar with struct markup, but you should be able to apply the same concept. If not, this article will be helpful to use the <label> and <input> tags to accomplish what you want.

    Try this:

    HTML:

    <table>
       <tr>
          <td>
             <label><span class="diff-color">*</span> Bank Name</label>
          </td>
       </tr>
    </table>
    

    CSS:

    span.diff-color {
        color: red;
    }
    

    That will set the color of all span elements with class name "diff-color" to red.

    Example.

    0 讨论(0)
提交回复
热议问题