0

I have an asp.net web form and I want to set the same background color to all the buttons in the form using CSS.This is what I have tried:

CSS:

body 
{
background-color:#336699;
}

.button 
{  
   background-color: #336699;   
   color: white;  
}

.button:hover 
{   
   background-color: White;
   color :#336699 
}

Page Source:

<head runat="server">
<title>Untitled Page</title>
<link href="../Layout.css" rel="stylesheet" type="text/css" />
</head>

Button Markup:

<asp:Button ID="btnSave" runat="server" Font-Bold="True" Height="40px" 
                            OnClick="btnSave_Click" Text="Save" 
Visible="False"     Width="90px" />

The background color for the body is applied successfully,but for buttons this code is not working.Please let me know how to do this.

4
  • 1
    It would be helpful to see the buttons' markup Commented Jun 13, 2014 at 12:58
  • Why is the button not visible? Commented Jun 13, 2014 at 13:02
  • 1
    The button doesn't seem to have the "button" class applied? Try adding CssClass="button" to the <asp:Button> tag? Commented Jun 13, 2014 at 13:03
  • That's the mistake I made, rather silly one.Thanks @xec Commented Jun 13, 2014 at 13:09

3 Answers 3

2

Note how your stylesheet declares styles. This:

body

is a set of styles to be applied to a tag body. However this:

.button
.button:hover

is a class, it will be applied only to those elements which have this class declared. SO you need to make sure the button has this class:

<asp:Button ... CssClass="button"
Sign up to request clarification or add additional context in comments.

Comments

1

Add Css Class selector to your button

<asp:Button CssClass="buttonClass" ID="btnSave" runat="server" Font-Bold="True" Height="40px"                                 OnClick="btnSave_Click" Text="Save" Visible="False" Width="90px"  />

then add design your class in your style

.buttonClass
{
   background-color:red;
}

Comments

-1

here might be a fix to <input type="button" class="button"> - but if there is, I don't know it.

.button 
{
   background-color: #E3E1B8; 
   padding: 2px 4px;
   font: 13px sans-serif;
   text-decoration: none;
   border: 1px solid #000;
   border-color: #aaa #444 #444 #aaa;
   color: #000
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.