簡體   English   中英

CSS類適用,但不適用id

[英]CSS class applying but not id

我目前正在構建測驗,因此我想將相同的類但具有不同的ID應用於三個文本輸入。 但是,由於某種原因,我的類CSS正在應用,但我的id未應用。 HTML:

            <form>
                <input id="0" class="textbs" type="text" >
                <input id="1" class="textbs" type="text">
                <input id="2" class="textbs" type="text">
                <input type="button" id="submmit" value="GO">
            </form>

CSS:

.textbs {
    height: 50px;
    width: 400px;
    font-size: 25px;
    font-family: geneva;
    border: solid rgba(255, 0, 0, 0.54);
    border-width: 5px;
    border-radius: 7px;
    position: absolute;
    margin-top: 150px;
    padding-left: 50px;
}

#0 {
    background-color: black;
}

#1 {
    display: none;
}

#2 {
    display:none;
}

我嘗試將#0 background-color更改為black,以查看是否識別出輸入ID,並保持白色(默認),但是當我添加了background-color:black; 行到它應用的.textbs。 請幫助!

ID不應以數字開頭,盡管您仍然可以嘗試以下操作:

[id='0'] {
 /* should work */
}

 #0 {
  /* shouldn't work */
}

演示

ID不能以數字開頭。

如果需要,將它們更改為“一個”,“兩個”,“三個”等。

請提供ID作為標識符,以字母或特殊字符“ _”開頭。 並且位置:“絕對”不是必需的。 嘗試這個。

<form>
                <input id="a0" class="textbs" type="text" >
                <input id="a1" class="textbs" type="text">
                <input id="a2" class="textbs" type="text">
                <input type="button" id="submmit" value="GO">
            </form>
.textbs {
    height: 50px;
    width: 400px;
    font-size: 25px;
    font-family: geneva;
    border: solid rgba(255, 0, 0, 0.54);
    border-width: 5px;
    border-radius: 7px;

    margin-top: 150px;
    padding-left: 50px;
}

#a0{
    background-color: black;
}

#a1 {
    display: none;
}

#a2 {
    display:block;
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM