【问题标题】:Page layout issues with PHP , HTML, and CSSPHP、HTML 和 CSS 的页面布局问题
【发布时间】:2011-02-01 08:02:24
【问题描述】:

由于某种原因,我的 CSS 没有将我的 div 标签格式化为页面上的正确位置。它适用于我的所有其他页面,但是这个页面中的 PHP 比正常页面要多得多,我想知道这是否是问题所在。 页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
    require("protect/serverInfo.php");
    $myusername=$_POST[Email]; 
    $mypassword=$_POST[Password];
    $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
    $count=mysql_num_rows($result);
    if($count==1){
        while($row = mysql_fetch_array($result)){
        ?>
        <div class="wrapper">
            <div class="customerHead">';
                <h1>  
                    <?php echo $row['Customer'] ?> 
                </h1>
            </div>
            <div class="customerInfoMain">
                 Company: <?php echo $row['Company'] ?><br />
                  State: <?php echo $row['State'] ?>
            </div>  
            <div class="customerCards">';
                 <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                 <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
            </div>  
            <div class="customerComments">';
                <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
            </div>
        </div>
    <?php   
        }
    }
    else {
        echo "Wrong Username or Password";
    }
?>

</body>

</html

>

CSS

.customerCards{
    top: 150px;
    position: relative;
    width: 425px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:1;
}
.customerInfoMain{
    top: 200px;
    position: relative;
    width: 200px;
    left: 520px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}
.customerComments{
    position: relative;
    width: 200px;
    left: 580px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}

.wrapper{
    position: absolute;
    left: 50%;
    width: 900px;
    margin-left: -475px;
}

页面加载后的来源

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">



<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

</head>



<body>

Wrong Username or Password

</body>



</html>

【问题讨论】:

  • PHP 在服务器端运行,并且永远不会出现在输出中。您需要查看生成的 HTML(并可能在此处发布)
  • 我在页面加载后发布了页面源代码
  • 在您发布的标记上没有任何内容可供 CSS 使用。
  • 好吧,这里的身份验证失败,这就是为什么你没有看到你的 css 魔法付诸行动。
  • 好吧,你已经发布了 else 生成的内容,我们应该如何理解它?

标签: php html css formatting


【解决方案1】:

它是因为如果有用户,你的包装器才刚刚启动.. 但是如果你把你的包装器放在 PHP 周围会发生什么,比如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="wrapper">
        <?php
        require("protect/serverInfo.php");
        $myusername=$_POST[Email]; 
        $mypassword=$_POST[Password];
        $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
        $count=mysql_num_rows($result);
        if($count==1){
            while($row = mysql_fetch_array($result)){
            ?>

                <div class="customerHead">';
                    <h1>  
                        <?php echo $row['Customer'] ?> 
                    </h1>
                </div>
                <div class="customerInfoMain">
                     Company: <?php echo $row['Company'] ?><br />
                      State: <?php echo $row['State'] ?>
                </div>  
                <div class="customerCards">';
                     <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                     <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                </div>  
                <div class="customerComments">';
                    <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
                </div>

        <?php   
            }
        }
        else {
            echo "Wrong Username or Password";
        }
        ?>
    </div>
</body>
</html>

“那你应该有一点 CSS 动作吗?”

【讨论】:

    【解决方案2】:

    按目的功能拆分代码和计算并不意味着在同一个地方,html应该最后呈现。继续这样工作会给你带来很多麻烦。事情应该是这样的:

    loginProcess.php 包含: if(isset($_SESSION["user"]) { $row = $_SESSION["user"]; } 包括(“loginPage.php”); ?>

    这是 longinPage.php(您可以在其中包含您想要的任何一个)。在 loginProcess.php 的末尾包含 loginPage.php 或在 loginPage.php 的开头包含 loginProcess.php

    所以 loginPage.php 包含

    无标题 1 <link href="stylesheet.css" rel="stylesheet" type="text/css"> <p> if(isset($_SESSION['user'])) { </p> <pre><code> < div class="wrapper"> < div class="customerHead">'; <h1><!---you know the row from before---/> <?php echo $row['Customer'] ?> </h1> </div> <div class="customerInfoMain"> Company: <?php echo $row['Company'] ?><br /> State: <?php echo $row['State'] ?> </div> <div class="customerCards">'; <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a> < a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"> </code></pre> <p></p> <pre><code> </div> <div class="customerComments">'; <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> </div> </div> <?php } } else {?> <form action="/loginProcess.php" (or loginPage.php if loginPage includes the loginProcess) method="POST"> <input type="text" name="Email" value=""/> <input type="password" name="Password" value=""/> <input type="submit" value="login"/> </form> <?php}?> </code></pre> <p>?></p> <p></p> <p></p> <p>首先将显示登录表单并且用户将输入他的凭据,这些凭据将被检查,如果它们没问题,则设置 SESSION['user'](请记住,您需要一个会话开始)现在只要由于会话持续存在,您将不需要一直请求登录。无论如何,如果您出于某种原因不想完全分离数据库关注点/流程关注点/查看关注点,至少您必须将流程与查看分开(将数据库关注点保留在处理区域中)。在线查看一些框架或尝试找到一种更谨慎地编写代码的方法,否则您将继续遇到无用的问题而浪费您的时间。</p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 2011-08-22
      • 1970-01-01
      相关资源
      最近更新 更多