我有以下代碼:HTML - 如何設置浮動元素的寬度爲其父文件夾的100%?
body{
\t \t \t margin:0;
\t \t }
\t \t #navbar{
\t \t \t background-color:red;
\t \t \t height:70px;
\t \t \t
\t \t \t width:80%;
\t \t \t margin:auto;
\t \t }
\t \t #search{
\t \t \t width:100%;
\t \t }
\t \t #element1{
\t \t \t height: 100%;
\t \t \t float:left;
\t \t \t background-color:green;
\t \t \t display: table;
\t \t }
\t \t #element2{
\t \t height: 100%;
\t \t \t float:left;
\t \t \t background-color:yellow;
\t \t \t display: table;
\t \t }
\t \t .v_center{
\t \t \t display: table-cell;
\t \t \t vertical-align: middle;
\t \t \t border-style: solid;
\t \t \t width:100%;
\t \t }
<!DOCTYPE HTML>
<HEAD>
\t <link rel="stylesheet" href="style.css" />
</HEAD>
<BODY>
\t <div id="navbar">
\t \t <!--<img src="http://www.findwatchdeals.com/media/logo.png" width="100px" height="50px"/>
\t \t <input type="search" id="search"/> -->
\t \t <div id="element1" >
\t \t \t <div class="v_center">
\t \t \t \t test
\t \t \t </div>
\t \t </div>
\t \t <div id="element2" >
\t \t \t <div class="v_center">
\t \t \t \t <input type="search" id=#search/>
\t \t \t </div>
\t \t </div>
\t \t <br style="clear:both;"/>
\t </div>
</BODY
</HTML>
我想我需要擺脫'浮動:左',但沒有它,他們不在彼此旁邊對齊。有人能幫我嗎?
'#{部件1寬度:10%;}#{element2的寬度:90%;}' – domsson