简体   繁体   English

如何将CSS应用于asp.net LinkBut​​ton?

[英]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. 我想创建一个css块,它将css class应用于整个网站上的所有<asp:LinkButton>

  • I can apply css for <asp:TextBox> throughout the website using below code single block. 我可以使用以下代码单个块在整个网站上为<asp:TextBox>应用css input[type="text"] {width:150px;}

Above code make width=150px to all asp textbox in my web site 上面的代码使我的网站中所有asp文本框的width=150px

The same way I want to write a css block which will apply to <asp:LinkButton> throughout the web site. 我想编写一个css块的方法相同,该块将应用于整个网站的<asp:LinkButton>

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: 由于asp.net中的<asp:LinkButton>呈现html中的anchor(<a>)标签,因此您可以将anchor(<a>)标签的css指定为:

a{
  color:red;
}

LinkButton control is a control just like a Button control along with the flexibility to make it look like a Hyperlink. LinkBut​​ton控件就像Button控件一样,它具有使它看起来像Hyperlink的灵活性。 It implements an anchor tag that uses only ASP.NET postback mechanism to post the data on the server. 它实现了一个仅使用ASP.NET回发机制将数据发布到服务器上的锚标记

its same as an anchor <a> tag so apply css style for 它与锚<a>标记相同,因此将CSS样式应用于

    a{
    //your style
    }

In asp.net there is inbuilt property called CssClass , you can use that. 在asp.net中,有一个名为CssClass内置属性,您可以使用它。 Here is the example how to use that: 这是示例如何使用它:

CSS: CSS:

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

HTML: 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. 最好的事情是,您可以使用相同的类,并以相同的方式将相同的类应用于多个asp.net控件。

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM