2014-04-02 52 views
1

下面的代碼是我到目前爲止我的css按鈕的配置,它現在顯示的是正常按鈕。但是,如果我切換到id而不是class,它確實有效。爲什麼我的asp按鈕(input type =「submit」)對我的css類沒有反應?

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

這是我的HTML

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

即使我把按鈕股利外,或將input[type=submit]相反,它仍然是行不通的。

+0

設置改爲使用CssClass屬性的CSS類。 –

+0

@KingKing如果屬性值中沒有特殊字符,我相信引號是不必要的。雖然它們也不會傷害它們。 –

+0

@FabrícioMatté是的,我習慣於添加引號,因爲這是一個非常好的做法,不使用引號是某種不好的做法,應該避免。 –

回答

2

刪除空格:

.phasesButton[type=submit] 

白色空間是後代選擇,也就是選擇:

.phasesButton [type=submit] 

會尋找匹配[type=submit]一個.phaseButton內的元素。

Reference

1

首先除去CSS選擇之間的空間。 秒type=submit將無法​​正常工作。它更改爲type=button

變化.phasesButton [type=submit].phasesButton[type=button]

說明:

  1. .phasesButton[type=button]這兩者是選擇器,用於相同元件,從而不應該被分離。

  2. 當您在網絡表單中添加一個標籤asp:button,在asp.net將呈現一個input type="button"爲你當你點擊這個按鈕,它會提交一篇文章到同一個頁面(這就是所謂postback),並會處理與此按鈕關聯的生命週期和asp.net事件。這同樣適用於每一個服務器控件,如TextBoxes(渲染input type='text'),​​(呈現的div),Checkboxes(渲染input type='checkbox'Labels(渲染spans)等等

reference

+0

嗯,你可以說'asp:button'呈現爲'type = button'而不復制[這個其他答案]的一半(http://stackoverflow.com/a/14306741/1331430)。 –

相關問題