How to change Label width using CSS in asp.net

asp.net example - label width css
this example shown how can we change the asp.net label server control width using simple css. here we uses label control style property. and we add a css style on style property. when someone click a button control, it programmatically change the label control's width. to apply this we need to write a css style section on web pages header section.
label-width-css.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.CssClass = "LabelWidthStyle";

        //another way to apply css style in label control.
        //Label1.Style.Add("width","475px");
    }  
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <style type="text/css">
        .LabelWidthStyle {
            width:475px;
        }
    </style>      
    <title>asp.net example - label width css</title>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - label width css
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <asp:Label       
            ID="Label1"       
            runat="server"      
            Text="sample label to test label css width."
            BorderColor="Red"
            BorderWidth="1"
            Font-Size="X-Large"
            >      
        </asp:Label>      
        <br /><br /><br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="label width css"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>      
    </form>      
</body>      
</html>
More asp.net examples