2012-05-17 48 views
1
<div id="header"> 
     <div id="search" style="float:right;width:250px;padding:20px 6px 6px 6px;"> 
      <form action="/" method="get" id="frmSiteSearch" name="frmSiteSearch"> 
       <input type="text" id="searchbox" name="keyword" size="20"/> 
       <div style="width:22px;height: 19px; float:left;background-color:green;"> 
       </div> 
      </form> 
     </div>   
    </div> 

jsbin hereCSS - 將div對齊文本框的右側

我想讓綠色背景的div出現在文本框的右側。

回答

3

浮動輸入左:

<input type="text" id="searchbox" name="keyword" size="20" style="float:left;"/> 

Example here

+0

感謝@ManseUK。有用。 10分鐘後我會接受。 – SyAu

2

這裏是http://jsfiddle.net/Jams/Xns64/鏈接

<div id="header"> 
     <div id="search" style="float:right;width:250px;padding:20px 6px 6px 6px;"> 
      <form action="/" method="get" id="frmSiteSearch" name="frmSiteSearch"> 
       <input type="text" id="searchbox" style="float:left;" name="keyword" size="20"/> 
       <div style="width:22px;height: 19px; float:left;background-color:green;"> 
       </div> 
      </form> 
     </div>   
    </div> 
+0

對不起,這是行不通的。 – SyAu

+0

@SyAu我已經更新了我的答案。現在它應該工作。 – jams

+0

完美。現在它可以工作。 – SyAu

0

更正代碼,綠色分度:

<div style="width:22px;height: 19px; float:right;background-color:green;"> 
+0

不工作。文本框和綠色div之間有一些空格。 – SyAu

+0

除了答案之外,請嘗試提供有關答案如何工作的解釋(或指出原因即鏈接) – javydreamercsw

2

看到代碼

<style>  
#searchbox, #button { 
    float:left; 
    width:150px; 
    height:19px; 
} 

    #button { 
    width:20px; 
    background:green; 
} 
    </style> 


     <div id="header"> 
      <div id="search" style="float:right;width:250px;padding:20px 6px 6px 6px;"> 
       <form action="/" method="get" id="frmSiteSearch" name="frmSiteSearch"> 
        <input type="text" id="searchbox" name="keyword" size="20"/> 
        <div id="button"> 
        </div> 
       </form> 
      </div>   
     </div> 

http://jsbin.com/igodip/11/edit

相關問題