如何为JSTL<c:if>标签内的文本设置CSS颜色?
解决方案
不需要更换<c:if>标签,直接在条件成立时显示的文本外层嵌套一个带内联CSS的<span>标签就能实现需求,不会影响labelOnLeft类下的其他内容。
修改后的代码片段如下:
<table> <c:if test="${testruns.employeecase != null}"> <tr><th colspan="2" class="labelOnLeft"> <label class="labelOnLeft"> <html:checkbox name="testruns" indexed="true" property="selectedCheckbox" /> <bean:write name="testruns" property="label" /> - <bean:write name="testruns" property="employeecase" /> <c:if test="${testruns.testAvailable}"><span style="color: red;">Test Available</span></c:if></label> <html:hidden name="testruns" indexed="true" property="label" /></th></tr>
说明
- 内联CSS的
style="color: red;"只会作用于<span>包裹的"Test Available"文本,不会影响<label>内的其他元素 - 原有的
<c:if>标签逻辑完全保留,仅对条件成立时输出的内容做样式包裹
内容的提问来源于stack exchange,提问作者Tan
相关产品推荐
相关产品推荐

