2017-11-26 10 views
-1

私は入力要素とそれの隣にボタン要素を持っています。
ボタンを固定サイズ(デフォルトサイズ)にし、残りの幅を入力するようにします。要素の塗りつぶしスペースを作る

どうすればよいですか?

これは私のコードです:あなたは、単にこのようにフレックスに使用することはできません

 <div style="position: fixed; 
     bottom: 0px; 
     left: 0px; 
     right: 0px; 
     background-color:white; 
     max-width:500px;"> 
     <input type="text" #message style="height: 50px; float:right;" /> 
     <button mat-fab (click)="newMessage()" color="primary"> 
      <mat-icon>send</mat-icon> 
     </button> 
     </div> 
    </div> 
+1

。 ''要素は、閉じスラッシュを使用しないか、必要としません。あなたはこれをあなた自身で解決しようとしていません。スタックオーバーフローはコードを書くサービスではありません。 https://stackoverflow.com/help/how-to-ask – Rob

答えて

2

:また

div { 
 
    display: flex; 
 
} 
 

 
input { 
 
    flex: 1; /* this will make the input to take the remaining space*/ 
 
}
<div style="position: fixed; 
 
     bottom: 0px; 
 
     left: 0px; 
 
     right: 0px; 
 
     background-color:white; 
 
     max-width:500px;"> 
 
    <input type="text" style="height: 50px;" > 
 
    <button mat-fab (click)="newMessage()" color="primary"> 
 
      <mat-icon>send</mat-icon> 
 
     </button> 
 
</div>

フロートプロパティを使用する必要が、あなたは位置を制御することができますorderプロパティを使用します。

上記のコードは右に、ボタンが左にある下のボタンを示しています。あなたは無効なHTMLタグを使用している

div { 
 
    display: flex; 
 
} 
 

 
input { 
 
    flex: 1; /* this will make the input to take the remaining space*/ 
 
    order:1; 
 
}
<div style="position: fixed; 
 
     bottom: 0px; 
 
     left: 0px; 
 
     right: 0px; 
 
     background-color:white; 
 
     max-width:500px;"> 
 
    <input type="text" style="height: 50px;" > 
 
    <button mat-fab (click)="newMessage()" color="primary"> 
 
      <mat-icon>send</mat-icon> 
 
     </button> 
 
</div>

+0

偉大な、しかし、何らかの理由でボタンが左側になければならないのですか? (元のコード入力では右に浮かんでいますか?) – sinisake

+1

@sinisakeあなたはorderプロパティを使うことができます...これを入力 'order:1'に追加してください。ボタンや入力の順序を変更することで、その位置を制御することができます –

+1

@sinisake詳細を含めるように答えを更新しました;) –

関連する問題