2013-05-03 103 views
0

在IE中,這個代碼顯示了頂部DIV,它應該裏面的形式:窗體顯示

<div style = 'height:100px;background-color:#FF6600'> 
<form name = "search" action = "search_result.php" method = "get" style = "text-align:right;"> 
<input type = "text" name = "query" id = "query" maxlength = "100"> 
<br /> 
<input type = "radio" value = "Search users" name = "user" id = "user">&nbsp;<input type = "radio" value = "Search topics" name = "topics" id = "topics"> 
<input type = "Submit" value = "Go"> 
</form> 
</div> 

但在Chrome中,它顯示在div下面的表格。爲什麼要這樣做,我該如何解決?

編輯:我省略了一些echos的HTML一些PHP代碼。以下是我的完整代碼:

<!DOCTYPE html> 
<html> 
<body> 
<?php 
session_start(); 
$connect = mysql_connect('localhost','phpuser','mypss'); 
$db = mysql_select_db('phpuser'); 
echo "<div style = 'float:none;clear:both;height:100px;background-color:#FF6600'>"; 
if(isset($_SESSION['user'])&&$_SESSION['user']!="") 
{ 
echo "<a href = 'userinfo.php'>".$_SESSION['user']."</a>"; 
echo "&nbsp;"; 
echo "|&nbsp;"; 
echo "<a href = 'logout.php'>Log out</a>&nbsp;"; 
echo "|&nbsp;"; 
} 
echo "<a href = 'home.php'>Home</a>"; 
if(!isset($_SESSION['user'])||$_SESSION['user']=="") 
{ 
echo "&nbsp;|&nbsp;"; 
echo "<a href = 'login.php'>Log in</a>&nbsp;|&nbsp;"; 
echo "<a href = 'signup.php'>Sign up</a>&nbsp;"; 
} 

function trimtext($text) 
{ 
$newtext = substr($text,0,15); 
$newtext .= "..."; 
return $newtext; 
} 
?> 
<h1 style = "color:black">My blog</h1> 
<form name = "search" action = "search_result.php" method = "get" style = "text-align:right;"> 
<input type = "text" name = "query" id = "query" maxlength = "100"> 
<br /> 
<input type = "radio" value = "Search users" name = "user" id = "user">&nbsp;<input type = "radio" value = "Search topics" name = "topics" id = "topics"> 
<input type = "Submit" value = "Go"> 
</form> 
</div> 
</body> 
</html> 
+0

是不是形式的塊級元素?你的表單是否真的需要在div中? – 2013-05-03 12:46:42

+0

似乎顯示對我很好,http://jsfiddle.net/a3njc/ – Ryan 2013-05-03 12:49:20

+0

不是真的相關,但它是一個很好的做法,增加號碼到您的形式,如果你需要輸入之間更多的空間使用的CSS屬性,而不是
sylwia 2013-05-03 13:18:19

回答

0

您是否將任何浮點屬性應用於更接近該表單的元素?如果是這樣的話,嘗試添加<div style="float: none; clear: both;"></div>

只是刪除形式的父DIV和應用div的風格,形成自己。

+0

有一個標題。我省略了一些代碼,因爲它從PHP中迴應了很多。我現在編輯我的問題。 – imulsion 2013-05-04 07:16:23