简体   繁体   中英

How can I edit CSS on the fly with ASP.NET code?

想要编辑DIV大小,颜色,位置(绝对),高度/宽度等内容。

You can just output the CSS like any other with Response.Write or the <%= someValue %> methods.

Here are some of the other methods: http://cfouquet.blogspot.com/2006/06/making-dynamic-css-content-with-aspnet.html

I'm not sure of what you're trying to do with the information given, but to add css on the fly you can use jQuery to add the class to an element with those certain specifications.. you can have jquery wait in the background for something to happen on the client and just add the class with that certain style

Example:

<style>
 p { margin: 8px; font-size:16px; }
.color { color:blue; }

</style>

<script>
   $(document).ready(function(){
     $("#button1").click(function(){ 
      $("p:last").addClass("color");
   });
</script>

<p>Hello</p>
 <p>and</p>
<p>Goodbye</p>

If by "on the fly" you mean while the user is interacting with the page then you're going to need to use some javascript. I suggest learning jQuery as it provides an easy and effective way interact with the DOM.

Ryan, you may want to look into Themes if you want to change the appearance of your site based on user preferences (Learning about Skins can help as well but master themes first). This is really the right approach in the ASP.NET model unless you are looking just to adapt some specific output to certain data conditions.

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