首页 > Web开发 > 详细

Blazor入手教程(二)css和class绑定

时间:2020-11-23 17:03:12      阅读:29      评论:0      收藏:0      [点我收藏+]

Cssclass绑定

 

Blazor中的cssclass绑定还是比较便利的。方式也和vue 十分类似,感觉唯一区别就是Blazor中拼接时不用像vue那样用+加号拼接字符串

 技术分享图片技术分享图片

 

 

@page "/cssbinding"


<style scoped>
    .active{

        width:80px;
        height:80px;
    }
    .active2 {
        background-color:#ff6a00;
    }

</style>

<h3>绑定单个css属性</h3>
<div style="font-size:@(fontsize)px">文字大小</div> 

<h3 style="margin-top:100px">绑定多个css属性</h3>
<div style="@style.ToString()"></div> 


<h3 style="margin-top:100px">绑定多个class</h3>
<div class="@getClass()"></div>




@code {

    public class Style
    {
        public int height { get; set; } = 100;
        public int width { get; set; } = 100;
        public string color { get; set; } = "#ccc";
        public override string ToString()
        {

            return $"width:{width}px;height:{height}px;background-color:{color}";
        }
    }

    public int fontsize =30;
    public Style style = new Style();
    public string[] classArray = new string[] { "active", "active2" };
    public string getClass()
    {

        return string.Join(" ", classArray);
    }
}

  

 

Blazor入手教程(二)css和class绑定

原文:https://www.cnblogs.com/jimsfriend/p/14017016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!