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> 
4

1 回答 1

0

您是否有任何浮动属性应用于更接近该表单的元素?如果是这种情况,请尝试添加 <div style="float: none; clear: both;"></div>

或者

只需删除表单的父 div 并将 div 的样式应用于表单本身。

于 2013-05-03T13:25:46.930 回答