简体   繁体   中英

How to apply css to asp.net LinkButton?

I want to create a css block, which will apply css class to all <asp:LinkButton> throughout my web site.

  • I can apply css for <asp:TextBox> throughout the website using below code single block. input[type="text"] {width:150px;}

Above code make width=150px to all asp textbox in my web site

The same way I want to write a css block which will apply to <asp:LinkButton> throughout the web site.

Please give me suggestions.

Thanks.

Since <asp:LinkButton> in asp.net renders anchor(<a>) tags in html then you can specify css for anchor(<a>) tag as:

a{
  color:red;
}

LinkButton control is a control just like a Button control along with the flexibility to make it look like a Hyperlink. It implements an anchor tag that uses only ASP.NET postback mechanism to post the data on the server.

its same as an anchor <a> tag so apply css style for

    a{
    //your style
    }

In asp.net there is inbuilt property called CssClass , you can use that. Here is the example how to use that:

CSS:

<style type="text/css">
    .lnkStyle
    {
        color: Red;
        font-size: 14;
    }
</style>

HTML:

<asp:LinkButton ID="lnkButton" runat="server" Text="Sample Link" CssClass="lnkStyle"></asp:LinkButton>

Best thing is that you can use and apply same class to multiple asp.net control using same way same class.

Hope it helps!

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