dourou9477
2017-05-10 09:25
浏览 164
已采纳

如何使用外部CSS样式表的HTML和PHP

I'm trying to center the h3 element and "profile_content" div-id in the "profile" class using external style sheets. I know how to do it with just an html and css file but I get stumped when php gets involved! Please could you help me with the syntax as well so I know what to do in the future.

php code

<?php
    session_start();

    // Connect to the database with '$mysqli' as the connection variable name
    $mysqli = new mysqli ("localhost", "root", "", "folder");

    //Check connection
    // '$mysqli->connect_errno' = Returns the error code from last connect call
    // '->' is used to access an object method or property
    if ($mysqli -> connect_errno) {
        die('Connect Error: ' . $mysqli -> connect_errno);
    }
?>

<html>
    <header>
        <link rel = "stylesheet" type = "text/css" href = "mystyle_friends.css">
    </header>
    <div class = "heading">
    <h1>FRIENDS PAGE</h1>
    </div>


    <p>Welcome  <?php  echo $_SESSION['username'] ?></p>



    <div class = "profile_content">

        <div id = profile_heading>
        <h3>Profiles</h3>
        </div>

        <?php 
            //Perform query against database. Requires 2 parameters = (connection, query)
            $result = mysqli_query($mysqli, "SELECT * FROM users");
            while ($row = mysqli_fetch_array($result)) {
                echo "<div id = 'profile_data'>";
                echo "<p> First Name: " .$row ["user_f_name"] .  "</p>";//$user_first = $row["user_f_name"];
                echo "<p> Surname: " .$row ["user_surname"] .  "</p>";//$user_sur =  $row["user_surname"];
                echo "<p> Score: " .$row ["user_score"] .  "</p>";//$user_score = $row["user_score"];
                echo '<img src="data:user_images/jpeg;base64,' . base64_encode( $row['user_image'] ) . '" />';
                echo "</div>";
            }
        ?>

    </div>

css external style sheet

.heading {
    text-align: center;
}

.profile {
    border-style: solid;
    border-width: 5px;

}

h3. profile {
    text-align: center;
}

#profile_content. profile {
    text-align: center;
}

3条回答 默认 最新

相关推荐 更多相似问题