CSS 如何将css样式设置为asp.net按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12177630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:01:58  来源:igfitidea点击:

How to set css style to asp.net button?

asp.netcssbuttonaspbutton

提问by Sujanth

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:LinkButtonthose styles are working well.I don't want any themes or skins for styles.

我有一个 asp:Button,我在 中使用了带有 cssClass 属性的 css 样式asp:Button,但是这些样式不起作用。当我使用asp:LinkButton这些样式时,这些样式运行良好。我不想要任何样式的主题或皮肤。

This is my asp page:

这是我的asp页面:

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

This is my CSS:

这是我的 CSS:

.smallButton 
{
  //styles
}

When I change asp:Button to asp:LinkButton

当我将 asp:Button 更改为 asp:LinkBut​​ton

<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

样式运行良好。asp:Button 控件的唯一问题

采纳答案by Sujanth

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.......

这是我的问题的解决方案......感谢大家的宝贵答案......

回答by Priyank Patel

You can assign a classto your ASP.NETButton and then apply the desired style to it.

您可以class为您的ASP.NETButton分配一个,然后对其应用所需的样式。

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

CSS:

CSS:

.mybtn
{
   border:1px solid Red;
   //some more styles
}

回答by Shankar Gupta

You can use CssClassattribute and pass a value as a css class name

您可以使用CssClass属性并将值作为 css 类名传递

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

.button
{
     //write more styles
}

回答by Stephen DuMont

nobody wants to go to the clutter of using a class, try this:

没有人愿意去使用类的混乱,试试这个:

<asp:button Style="margin:0px" runat="server" />

Intellisense won't suggest it but it will get the job done without throwing errors, warnings, or messages. Don't forget the capital S in Style

Intellisense 不会建议它,但它会在不抛出错误、警告或消息的情况下完成工作。不要忘记 Style 中的大写 S

回答by Pir Fahim Shah

If you have a button in asp.net design page like "Default.asp" and you want to create CSS file and specified attributes for a button,labels or other controller. Then first of all create a css page

如果您在 asp.net 设计页面中有一个按钮,例如“Default.asp”,并且您想为按钮、标签或其他控制器创建 CSS 文件和指定属性。然后首先创建一个css页面

  1. Right click on Project
  2. Add new item
  3. Select StyleSheet
  1. 右键单击项目
  2. 添加新项目
  3. 选择样式表

now you have a css page now write these code in your css page(StyleSheet.css)

现在你有一个 css 页面,现在在你的 css 页面(StyleSheet.css)中编写这些代码

StyleSheet.css

样式表.css

.mybtnstyle
{
 border:1px solid Red;
 background-color:Red;
 border-style:groove;
 border-top:5px;
 outline-style:dotted;
}

Default.asp

默认.asp

{

{

  <head> 
  <title> testing.com </title>
 </head>
<body>
 <b>Using Razer<b/>
<form id="form1" runat="server">
 <link id="Link1" rel="stylesheet" runat="server" media="screen" href="Stylesheet1.css" />
 <asp:Button ID="mybtn" class="mybtn" runat="server" Width="339px"/>
 </form>
 </body>
</html>

}

}

回答by Remy

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

您可以在 css 文件中设置 input 元素的样式。然后独立于 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 CssClassyou can assign the "input"class to it.

使用CssClass可以将"input"类分配给它。

回答by Nandolcs

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"

回答by hitesh vikani

<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/

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