简体   繁体   中英

Creating a CSS class programmatically ASP.Net

I have a DIV that I would like to modify the CSS for programmatically in VB.Net/C#.

I know that, for example, I could add style attributes simply by

divMyDiv.Style.add("color","#ff0000")

but I want to add a new CSS class, together with its attributes to the DIV. So in an ideal world I would like to write something like

divMyDiv.Style.add(".smallRedText", "{font-size:10px; color:#ff0000}")

Is this even possible ? Am I missing the bigger picture ?

All help gratefully received :-)

关于什么:

divMyDiv.Attributes.Add("class", "new-class")

I suggest that you define the variations in css ahead of time that you know you'll need. Then, you can manipulate the class attribute of whatever control you need to change on the fly.

For example, you could define:

.smallRedText { font-size: 10px; color: #ff0000 }
.smallBlueText { font-size: 10px; color: #0000ff }

Then when comes time to select dynamically:

divMyDiv.Attributes.Add("class", whateverClassWeNeed);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM