为什么我的asp按钮(输入类型= "submit")对我的css类没有反应?



下面的代码是我到目前为止配置css按钮的代码,它现在显示的只是普通按钮。 但是,如果我切换到 id 而不是类,它确实有效。

.phasesButton [type=submit]
{
  clear:both;
  display:block;
  margin-left: auto;
  margin-right: auto;
  width:125px;
  height:31px;
  background:rgba(0,0,0, .7);
  text-align:center;
  line-height:31px;
  color:#FFFFFF;
  font-size:13px;
  font-weight:bold;
  margin-top:30px;
  border: 1px solid #000000;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .7), inset 0 1px 0 rgba(255, 255, 255, .5);
  cursor: pointer;
}

这是我的网页

 <div id="phaseOne" class="frmPhaseOne">
    <table width="95%">
    .
    .
    .
    </table>
    <asp:Button ID="btnPhaseOne" class="phasesButton " runat="server" Text="Submit"/>
</div>

即使我将按钮放在div 之外或input[type=submit]放置,它仍然不起作用。

删除空格:

.phasesButton[type=submit]

空格是后代选择器,即选择器:

.phasesButton [type=submit]

将寻找与.phaseButton内部[type=submit]匹配的元素。

参考

首先删除 css 选择器之间的空格。其次,type=submit不起作用。将其更改为type=button

.phasesButton [type=submit]更改为.phasesButton[type=button]

解释:

  1. .phasesButton[type=button]这两者是同一元素的选择器,因此不应分开。

  2. 当您在 Web 表单中添加标记asp:button时,asp.net 将为您呈现一个input type="button",当您单击此按钮时,它将向同一页面提交帖子(这称为postback),并将处理与此按钮关联的生命周期和 asp.net 事件。这同样适用于每个服务器控件,例如TextBoxes(渲染input type='text')、Panels(渲染div)、Checkboxes(渲染input type='checkbox')、Labels(渲染spans)等......

参考

最新更新