开发者

CSS not being applied to base page element when referenced by id

I have a Master Page which has an associ开发者_开发技巧ated css file. On one of the base pages I have a div to which I am trying to apply a style from this css file by id. However, the page when rendered has a different id for this element.

How can I specify the correct id name in the css file?

Is there a way to specify that I want the id of this element like there is in javascript using the <%= Element.ClientID %>?


As best practice you should use the CssClass property to handle the look and feel of page controls. And for the page UI use the ID property which are commonly not controls and have child elements.

Controls

<asp:Label id="lblTest" CssClass="label" runat="Server">Test</Label>

Parent Elements

<div id="someid">
      <asp:Label id="lblTest" CssClass="label" runat="Server">Test</Label>
</div>


You should be using class="someClass" for this instead of by the id. If you MUST use an id, put a container around it you know will not change, and give it an id, then do this

#myContainer .someClass {
...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜