2016-09-24 21 views
0

我正在練習HTML和CSS。我必須與以下代碼 -當屏幕很小時輸入框沒有填滿整個空間

.outer_class{ 
 
    \t \t position: absolute; 
 
    \t \t width: 50%; 
 
    \t \t height: 30%; 
 
    \t \t top: 35%; 
 
    \t \t left: 25%; 
 
    \t \t background-color: red; 
 
    \t } 
 
    \t .inner_class{ 
 
    \t \t position: relative; 
 
    \t \t width: 50%; 
 
    \t \t height: 50%; 
 
    \t \t top: 25%; 
 
    \t \t left: 25%; 
 
    \t \t background-color: yellow; 
 
    \t } 
 
    \t .div_input{ 
 
    \t \t position: relative; 
 
    \t \t width: 70%; 
 
    \t \t height: 50%; 
 
    \t \t top: 25%; 
 
    \t \t left: 15%; 
 
    \t \t background-color: blue; 
 
    \t } 
 
    \t input[type="text"]{ 
 
    \t \t box-sizing: border-box; 
 
    \t \t width: 100%; 
 
    \t \t height: 100%; 
 
    
 
    \t }
<!DOCTYPE html> 
 
    <html lang="en"> 
 
    <head> 
 
    \t <meta charset="utf-8"> 
 
    \t <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    \t <title>Align_Textbox_To_Div_Center</title> 
 
    \t <!--++++++++++++++++++++++Bootstrap CDN(Content Delivery Network)++++++++++++++++++++++++++++++--> 
 
    \t <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
 
    \t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
 
    \t <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 

 
    </head> 
 
    <body> 
 
    \t <div class="outer_class"> 
 
    \t \t <div class="inner_class"> 
 
    \t \t \t <div class="div_input"> 
 
    \t \t \t \t <input type="text" name="username"> 
 
    \t \t \t </div> 
 
    \t \t </div> 
 
    \t </div> 
 
    </body> 
 
    </html>

現在的一個問題,當我調整瀏覽器窗口最小,藍格的點點所示。爲什麼是這樣的,我該如何解決它?

在此先感謝!

+2

因爲你使用的引導,而不是將其相應的類相應的尺寸。 – Lahori

+0

@Lahori如果我不使用Bootstrap,我該如何解決這個問題,即使移除Bootstrap CDN部分後,它仍然會持續存在? –

+0

@Neferseti現在檢查它。刪除背景色fo .div_input – Dhaarani

回答

1

Add
input [type =「text」] { position:absolute; border:none; }

.outer_class{ 
 
    \t \t position: absolute; 
 
    \t \t width: 50%; 
 
    \t \t height: 30%; 
 
    \t \t top: 35%; 
 
    \t \t left: 25%; 
 
    \t \t background-color: red; 
 
    \t } 
 
    \t .inner_class{ 
 
    \t \t position: relative; 
 
    \t \t width: 50%; 
 
    \t \t height: 50%; 
 
    \t \t top: 25%; 
 
    \t \t left: 25%; 
 
    \t \t background-color: yellow; 
 
    \t } 
 
    \t .div_input{ 
 
    \t \t position: relative; 
 
    \t \t width: 70%; 
 
    \t \t height: 50%; 
 
    \t \t top: 25%; 
 
    \t \t left: 15%; 
 
      background:blue; 
 
    \t } 
 
    \t input[type="text"]{ 
 
    \t \t box-sizing: border-box; 
 
    \t \t width: 100%; 
 
    \t \t height: 100%; 
 
      position:absolute; 
 
      border:none; 
 
    \t }
<!DOCTYPE html> 
 
    <html lang="en"> 
 
    <head> 
 
    \t <meta charset="utf-8"> 
 
    \t <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    \t <title>Align_Textbox_To_Div_Center</title> 
 
    \t <!--++++++++++++++++++++++Bootstrap CDN(Content Delivery Network)++++++++++++++++++++++++++++++--> 
 
    \t <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
 
    \t <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
 
    \t <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 

 
    </head> 
 
    <body> 
 
    \t <div class="outer_class"> 
 
    \t \t <div class="inner_class"> 
 
    \t \t \t <div class="div_input"> 
 
    \t \t \t \t <input type="text" name="username"> 
 
    \t \t \t </div> 
 
    \t \t </div> 
 
    \t </div> 
 
    </body> 
 
    </html>

+0

@Dharaani這個解決方案只會讓div無形,但問題仍然存在。輸入框不在中間,這意味着div仍然存在,輸入框尚未佔用div_input的整個高度。 –

+0

我不明白你的問題。你有什麼期望?我認爲藍線是問題,所以我必須刪除它。現在你需要填充黃色空間的輸入 – Dhaarani

+0

藍色div位於黃色div的中心,它位於紅色div的中心。 我希望輸入框佔據整個藍色的div,這意味着輸入框顯示在黃色div的中心。 當屏幕被調整到最小值時,輸入框並未填滿整個藍色div,這使得看起來輸入框不在黃色div的中心。那就是問題所在。如何解決它? –