How to set css style to asp.net button?

2020-02-08 18:16发布

I have a asp:Button, I used css styles with cssClass property in asp:Button, but those styles are not working. When I use asp:LinkButton those styles are working well.I don't want any themes or skins for styles.

This is my asp page:

<asp:Button CssClass="smallButton" Text="Sign In" runat="server" ID="submit"></asp:Button>

This is my CSS:

.smallButton 
{
  //styles
}

When I change asp:Button to asp:LinkButton

<asp:LinkButton Text="Sign In" runat="server" ID="submit" CssClass="smallButton"></asp:LinkButton>

or

<span class="smallButton"><asp:LinkButton Text="Sign In" runat="server" ID="submit"></asp:LinkButton></span>

styles are working well. Only problem with the asp:Button control

8条回答
可以哭但决不认输i
2楼-- · 2020-02-08 18:26
<asp:LinkButton ID="mybutton" Text="Link Button" runat="server"></asp:LinkButton>

With Hover effects :

 #mybutton
        {
            background-color: #000;
            color: #fff;
            font-size: 20px;
            width: 150px;
            font-weight: bold;
        }
        #mybutton:hover
        {
            background-color: #fff;
            color: #000;
        }

http://www.parallelcodes.com/asp-net-button-css/

查看更多
够拽才男人
3楼-- · 2020-02-08 18:29

The answer you mentioned will be applied to all buttons. You should try this:

input[type="submit"].someclass {
    //somestyle}

And make sure you add this to your button:

CssClass="someclass"
查看更多
三岁会撩人
4楼-- · 2020-02-08 18:31

You could just style the input element in your css file. That is then independent of ASP.NET.

<form action="">
    Name: <input type="text" class="input" />
    Password: <input type="password" class="input" />
    <input type="submit" value="Submit" class="button" />
</form>
CSS
.input {
    border: 1px solid #006;
    background: #ffc;
}
.button {
    border: 1px solid #006;
    background: #9cf;
}

With the CssClass you can assign the "input" class to it.

查看更多
做自己的国王
5楼-- · 2020-02-08 18:32

I Found the coding...

 input[type="submit"]
    {
     //css coding
    }
 input[type="submit"]:Hover  
    {
     //css coding
    }

This is the solution for my issue..... Thanks everyone for the valuable answers.......

查看更多
6楼-- · 2020-02-08 18:36

You can use CssClass attribute and pass a value as a css class name

<asp:Button CssClass="button" Text="Submit" runat="server"></asp:Button>` 

.button
{
     //write more styles
}
查看更多
我只想做你的唯一
7楼-- · 2020-02-08 18:37

You can assign a class to your ASP.NET Button and then apply the desired style to it.

<asp:Button class="mybtn" Text="Button" runat="server"></asp:Button>

CSS:

.mybtn
{
   border:1px solid Red;
   //some more styles
}
查看更多
登录 后发表回答