HTML呈现错误

时间:2013-09-05 00:16:55

标签: html rendering

我在我的网站上工作,发现<center>标签无法正常工作。我的元素包含在<div id="main'><center>标签中,并且所有文本行都没有正确排列。

<?php
    require('/inc.all.php');
    $_SESSION['lastUrl'] = $_SERVER['REQUEST_URI'];
    // Get total count of rows
    $sql = "SELECT COUNT(username) FROM user_profile WHERE hideFromUserCount='0'";
    $query = $db->query($sql);
    $row = $query->fetch_row();
    // Total row count
    $rows = $row[0];
    //Number of results per page
    //if($rows < 10){
    //  $page_rows = $rows -1;  
    //}else{
        $page_rows = 10;
    //}

    //Tells us number of last page
    $last = ceil($rows/$page_rows);

    if($last < 1)
        $last = 1;  
    //Establish $pagenum variable
    $pagenum = 1;

    if(isset($_GET['pg']))
        $pagenum = preg_replace('#[^0-9]#', '', $_GET['pg']);
    else
        $pagenum = 1;

    //Makes sure pagenumber isnt below 1 or more than $last
    if($pagenum < 1)
        $pagenum = 1;
    else if($pagenum > $last) 
        $pagenum = $last;

    //Sets range of rows for chosen $pagenum
    $limit = 'LIMIT '.($pagenum-1) * $page_rows.','.$page_rows;
    $sql = "SELECT username FROM user_profile WHERE hideFromUserCount='0' ORDER BY username ASC $limit";
    $query = $db->query($sql);
    $show_start = $pagenum * $page_rows;
    $show_end = (($pagenum * $page_rows) + $page_rows)-1;
    $textline1 = "Total Profiles: <b>$rows</b>";
    $textline2 = "Page <b>$pagenum</b> of <b>$last</b>";

    $paginationCtrls = '';
        if($pagenum > 1){
            $previous = $pagenum-1;
            $paginationCtrls .= "<li><a href=\"?pg=$previous\">Prev</a></li>";
            for($i = $pagenum-4; $i < $pagenum; $i++){
                if($i > 0){
                    $paginationCtrls .= "<li><a href=\"?pg=$i\">$i</a></li>";
                }
            }
        }else{
            $previous = $pagenum-1;
            $paginationCtrls .= "<li class='disabled'><a href=\"#\">Prev</a></li>"; 
        }

        $paginationCtrls .= "<li class='disabled'><a href=\"#\">$pagenum</a></li>";

        for($i = $pagenum+1; $i<=$last; $i++){
            $paginationCtrls .= "<li><a href=\"?pg=$i\">$i</a></li>";
            if($i >= $pagenum+4){
                break;  
            }
        }

        if($pagenum != $last){
            $next = $pagenum +1;
            $paginationCtrls .= "<li><a href=\"?pg=$next\">Next</a></li>";  
        }else{
            $next = $pagenum +1;
            $paginationCtrls .="<li class=\"disabled\"><a href=\"#\">Next</a></li>";    
        }
        $usernames = "";
        while($row = $query->fetch_assoc()){
            $username = $row['username'];
            $usernames .="<br><a href=\"viewProfile?usr=$username\">$username</a><br>"; 
        }

?>
<!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>
    <title>Minecraft Profiles | Profiles</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="style/css/style_viewProfile.css">
    <link href="style/css/bootstrap.css" rel="stylesheet" type="text/css">
</head>

<body>
<!--<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <a class="brand" href="index">Minecraft Profiles</a>
        <ul class="nav">
            <li><a href="index">Home</a></li>
            <li class="active"><a href="profileList">Profiles</a></li>
            <li><a href="userLookup">Find User</a></li>
            <li><a href="createProfile">Create a Profile</a></li>
            <li><a href="dashboard">User Dashboard</a></li>
            <?php
                if(isset($_SESSION['username']) && isset($_SESSION['password'])){
                    echo "<li><a href=\"logout\"> Welcome Back, ".$_SESSION['username']."! Click to log out</a></li>";
                }else{
                      echo "<li><a href=\"login\">Login</a></li>";
                }
            ?>
        </ul>
  </div>
</div>-->
<br />
<br />
    <div id="header">
        <h1>Profiles</h1>
    </div>
    </div>
    <div id="content">
        <div id="sidebar">
            <strong>Featured Profiles</strong>
            <br />
            <?php 
                $sql = "SELECT username FROM user_profile WHERE featured = 1";
                $query = $db->query($sql);
                while($row = $query->fetch_assoc()){
                    $username = $row['username'];
                    echo "<a href=\"viewProfile.php?usr=$username\">$username</a>";
                    echo "<br />";
                }
            ?>
        </div>
        <div id="main">
            <center>
            <?php echo $textline1;?><br />
            <?php echo $textline2; ?><br />
            <?php if(isset($usernames)) {echo $usernames; }?><br />
            <div class="pagination"><ul><?php echo $paginationCtrls; ?></ul></div></center>
        </div>
        <div class="clear">
       <?php
            $sql="SELECT * FROM user_profile WHERE hideFromUserCount = 0";
            $query=$db->query($sql);
            echo "<div class=\"clear\"><br /><center>Minecraft Profiles is proud to have ".$query->num_rows." unique profile(s) registered in our databases!</center></div>";
        ?>
      </div>
    </div>

</body>

</html>

$textline1$textline2只是在屏幕上显示一些文字。最终结果类似于This

1 个答案:

答案 0 :(得分:0)

您是否尝试删除&lt; center&gt;完全和造型div?

<div id="main" style="text-align: center;">

另外 - 你需要#main有一个宽度,所以CSS知道文本的中心宽度