Reputation: 2861
So i know in that i can design a style for a HTML control by either using CSS-class or CSS-id association.
For instance, HTML:
CSS:div
{
position: absolute;
}
div#divHeader
{
left: 1px;
right: 1px;
top: 5px;
min-width: 90%;
height: 100px;
text-align: center;
}
HTML:
<div id="divHeader">
...
</div>
Can i use this same Association for ASP.Net controls or will i have to implicitely declare the association with the CSSClass attribute?
CSS:#lblTitle
{
width: 100px;
}
HTML:
...
<td id="tdTitle">
<asp:Label ID="lblTitle" Style="font-size: 46pt; vertical-align: middle;" runat="server" />
</td>
...
I would assume it would work but need some verification. If i have to use the CSSclass attribute i will but would rather reserve that attribute for other generic style development.
Upvotes: 0
Views: 433
Reputation: 17614
Can i use this same Association for ASP.Net controls or will i have to implicitely declare the association with the CSSClass attribute?
Answer is yes.
But as you might be kowing div#divHeader
is a id css. It will be applied to the every div
having the id divHeader
.
But you should aslo be knowing the difference between a html-control
and asp.net control
.
The id
attribute changes at runtime in asp.net that can be due to many reasone.
master
and content pages
.user controls
.gridview
or similar controls. In the condition 1
and 2
you can use static id
if you are using asp.net 4.o and above as follows.
ClientIDMode =static
But in case of gridview you can use parent child or herical approach. You will have to understand the rendering of html on the browser.
Only then you will able to create a good css classes.
Upvotes: 1
Reputation: 1662
You have a couple of options:
Option 1 wouldn't be an issue really when using classes, aside from having to put class="yourclass" on your controls tag. I tend to stray away from ID tags unless there is a defined reason for styling just this one element.
Option 2: You would have to go in and figure out how to hierarchically define your css based on the rendered HTML from your form; figuring out that "" when rendered, etc.
Upvotes: 1