2016-07-24 10 views
1

かなり簡単です。個々の入力ボックスのサイズを変更しようとしていますが、クラスを使用してサイズを変更しようとすると、すべてのボックスのサイズが変更されます。何が間違っているか分かりません。ここでは、コードです:個々の入力ボックスのサイズが変更されず、他のサイズ変更も行われません。

/* Centre the page */ 
 
    .body { 
 
     margin: 0 auto; 
 
     width: 450px; 
 
     top: 50px; 
 
     background-color: #444; 
 
     overflow: hidden; 
 
     position: relative; 
 
     display: block; 
 
     padding: 5px; 
 
    } 
 

 
    /* Centre the form within the page */ 
 
    form { 
 
     margin:0 auto; 
 
     text-align: center; 
 
    } 
 

 
    /* Style the text boxes */ 
 

 
    input, textarea { 
 
     height:30px; 
 
     background:#444; 
 
     border:1px solid white; 
 
     padding:10px; 
 
     font-size:1.4em; 
 
     color:white; 
 
     font-family: 'Lato', sans-serif; 
 
    } 
 

 
    input:focus, textarea:focus { 
 
     border:1px solid white; 
 
     color: white; 
 
    } 
 

 
    #submit { 
 
     height: 50px; 
 
     cursor: pointer; 
 
    } 
 

 
     #submit:hover { 
 
     background-color:#005f5f ; 
 
    } 
 

 
    .info { 
 
     size: 175px; 
 
    } 
 

 
    .message { 
 
     size: 400px; 
 
    }
<div class="body"> 
 
\t \t <form method="post" action="../php/index.php"> 
 
     
 
    \t \t <input class="info" name="name" placeholder="What's your name?"> 
 
      
 
    \t \t <input class="info" name="email" type="email" placeholder="What's your email?"> 
 
      
 
    \t \t <textarea class="message" name="message" placeholder="How can I help?"></textarea> 
 
      
 
    \t \t <input class="info" id="submit" name="submit" type="submit" value="Submit"> 
 
     
 
\t \t </form> 
 
\t </div>

任意の助けをいただければ幸いです。私はコードが乱雑であることを知っている、私はすべてを試してきたので、私はそれをきれいにする時間がなかった。前もって感謝します!

答えて

0

sizeは、あなたのHTML入力をサイジングする正確な方法ではありませんaccording to the HTML specification。 入力の幅を調整するには、例:width: 10emまたはwidth: 20pxを使用することをおすすめします。

CSSの場合、name属性を使用して、異なる幅の要素を指定できます。また、働く異なる要素ごとに異なるclass nameを持つ

.info[name='email'] { 
    width: 12em; 
} 

.info[name='name'] { 
    width: 13em; 
} 

<input class="info" name="name" placeholder="What's your name?">    
<input class="info" name="email" type="email" placeholder="What's your email?"> 

.info-long { 
    width: 130px; 
} 

.info-short { 
    width: 100px; 
} 

<input class="info-long" name="name" placeholder="What's your name?">    
<input class="info-short" name="email" type="email" placeholder="What's your email?"> 

異なる幅の入力フォームの例については、次のスニペットを実行してください。

/* Centre the page */ 
 
    .body { 
 
     margin: 0 auto; 
 
     width: 450px; 
 
     top: 50px; 
 
     background-color: #444; 
 
     overflow: hidden; 
 
     position: relative; 
 
     display: block; 
 
     padding: 5px; 
 
    } 
 

 
    /* Centre the form within the page */ 
 
    form { 
 
     margin:0 auto; 
 
     text-align: center; 
 
    } 
 

 
    /* Style the text boxes */ 
 

 
    input, textarea { 
 
     height:30px; 
 
     background:#444; 
 
     border:1px solid white; 
 
     padding:10px; 
 
     font-size:1.4em; 
 
     color:white; 
 
     font-family: 'Lato', sans-serif; 
 
    } 
 

 
    input:focus, textarea:focus { 
 
     border:1px solid white; 
 
     color: white; 
 
    } 
 

 
    #submit { 
 
     height: 50px; 
 
     cursor: pointer; 
 
    } 
 

 
     #submit:hover { 
 
     background-color:#005f5f ; 
 
    } 
 

 
    .info[name="name"] { 
 
     width: 13em; 
 
    } 
 

 
    .info[name='email'] { 
 
     width: 12em; 
 
    } 
 

 
    .message { 
 
     width: 400px; 
 
    }
<div class="body"> 
 
\t \t <form method="post" action="../php/index.php"> 
 
     
 
    \t \t <input class="info" name="name" placeholder="What's your name?"> 
 
      
 
    \t \t <input class="info" name="email" type="email" placeholder="What's your email?"> 
 
      
 
    \t \t <textarea class="message" name="message" placeholder="How can I help?"></textarea> 
 
      
 
    \t \t <input class="info" id="submit" name="submit" type="submit" value="Submit"> 
 
     
 
\t \t </form> 
 
\t </div>

0

すべての入力のクラスは同じです。情報同じクラスを持つすべての入力は同じスタイルになります。したがって、サイズ変更はそれらのすべてに適用されます。サイズを変更するか、あらかじめidに与えたい入力に別のクラスを与え、CSSを使ってサイズを変更します。 infoは内部に指定された幅しか持たないので、他の面は変更されません。

関連する問題