如何在< h:inputText>上应用CSS? [英] How apply CSS on a <h:inputText>?
问题描述
我正在尝试将CSS应用于我的<h:inputText>
,但到目前为止没有成功:
I'm trying to apply CSS to my <h:inputText>
but without success so far :
<h:form id="contactform">
<h:panelGrid columns="3">
<h:outputLabel for="name">Name</h:outputLabel>
<h:inputText id="name" value="#{contact.client.name}" >
<f:ajax event="blur" render="nameMessage"></f:ajax>
</h:inputText>
<h:message id="nameMessage" for="name" />
<h:commandButton value="Send" action="#{contact.sendMessage}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:messages globalOnly="true" layout="table" />
</h:form>
我的CSS:
#contactform .text-input{
background-color:#fbfbfb;
border:solid 10px #000000;
margin-bottom:8px;
width:178px;
padding:8px 5px;
color:#797979;
}
如果我尝试在某些HTML输入字段中应用此CSS样式,那么它将起作用,但在JSF 2.0中则无效.
If i try to apply this CSS style in some HTML input field it works, but not in JSF 2.0.
在JSF中更新我的代码的这一部分:
Update this part of my code in JSF:
<h:inputText id="name" styleClass="text-input" value="#{contact.client.name}" >
将此代码插入我的CSS文件:
Insert this code in my CSS file:
text-input{
border:solid 1px #e0e0e0;
}
但似乎是同一件事,没有任何改变.
But it seems the same thing, nothing change.
输出:
<form id="j_idt35" name="j_idt35" method="post" action="/brainset/contact.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt35" value="j_idt35" />
<table class="contactform">
<tbody>
<tr>
<td><label for="j_idt35:name"> Name</label></td>
<td><input id="j_idt35:name" type="text" name="j_idt35:name" class="text-input" onblur="mojarra.ab(this,event,'blur',0,'j_idt35:nameMessage')" /></td>
<td><span id="j_idt35:nameMessage"></span></td>
</tr>
</form>
这里有些奇怪. 在你们的帮助下更新我的代码:
There is something weird here. Update my code with the help of you guys:
<h:form>
<h:panelGrid id="contactform" styleClass="contactform" columns="3">
<h:outputLabel for="name">Nome</h:outputLabel>
<h:inputText id="name" value="#{contact.client.name}" >
<f:ajax event="blur" render="nameMessage"></f:ajax>
</h:inputText>
<h:message id="nameMessage" for="name" />
</h:panelGrid
</h:form>
所以我的CSS样式现在是这种方式:
so my CSS style is now this way:
.contactform .text-input{
background-color:#fbfbfb;
border:solid 50px #000000;
margin-bottom:8px;
width:178px;
padding:8px 5px;
color:#797979;
}
如果我在特定的输入文本中应用css样式,则它可以工作,但不应该将其应用于表中下面的所有输入文本?
if i apply the css style in a specific input-text it works, but it shouldn't apply to all input-text below in my table ?
有什么主意吗?
推荐答案
默认情况下,输出<h:inputText ...>
不应具有任何class
属性.您可以通过在JSF标记中定义styleClass
属性来添加class
属性
The output <h:inputText ...>
should not have any class
attribute by default. You can add a the class
attribute by defining a styleClass
attribute in the JSF tag
<h:inputText id="name" styleClass="text-input" value="#{contact.client.name}" >
</h:inputText>
请参阅参考详细信息
这篇关于如何在< h:inputText>上应用CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!