开发者

Is it possible to use 'variables' for css / html element?

i would like to make 'skinnable' a web site written in asp.net... I explain: for example, i have a 'div' element, and i would like to define a background-color using a variable, not a fixed value. How can i do ? Css ? Or othe开发者_C百科r tecniques ? Thanks


CSS is exactly what your are looking for.

Keep in mind that when writing your classes and ids you should refer to the element semantically. It means you should NOT choose your names depending on the visual representation of the element.

Wrongs:

  • .blue
  • boxOnLeft

Goods:

  • .comments
  • related

To be able to skin your page, you'll just need to change your css. Almost all is possible using CSS.


ASP.NET has built-in functionality for Themeing and Skinning:

ASP.NET Themes and Skins - MSDN

You could always roll your own as well. The general idea is that you have a seperate set of CSS for each Theme/Skin and then generate the references dynamically based on what Theme/Skin the user selects.


You might look at .Less and t4 template package for it:
http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx

A lot of good notes in the comments of that link as well, including a visual studio addin.


CSS doesn't have programming variable capabilities that you hope to achieve.

However, there is a way to do this with PHP (I know you're looking for .NET solution here, but bear with me)

Basically, you add a line of header text "", save the css with .php extension, and then load the .php in html as css (""). Then you can manipulate variables with PHP.

I don't know anything about .NET, but I believe it should be possible in a similar manner.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜