2017-05-10 12 views
0

外部スタイルシートを使用して、h3要素と "profile_content" div-idを "profile"クラスに集中させようとしています。私はちょうどhtmlとcssファイルでそれを行う方法を知っていますが、PHPが関わったときに困惑します!文法を教えてもらえますか?今後の対応について教えてください。htmlとphpの外部CSSスタイルシートの使い方

PHPコード

<?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外部スタイルシート

.heading { 
    text-align: center; 
} 

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

} 

h3. profile { 
    text-align: center; 
} 

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

mxr7350 @ - これらの引用符が100%オプションです。それらは紛失することが許されており、それらを追加することで(ファイルサイズに数バイトを追加することを除いて)差は出ません。 – Quentin

+1

あなたのCSSには[エラー数](https://jigsaw.w3.org/css-validator/)があり、PHPがどのように問題に影響するかはわかりません。 – Quentin

+0

」の代わりに「」を試してください。また、 ''が必要です。 – Huelfe

答えて

1

ホリーマカロニ

を、ファイルを保存するまず、あなたのHTMLを修正します!

<?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> 
    <head> 
     <link rel="stylesheet" type="text/css" href="mystyle_friends.css"> 
    </head> 
    <body> 
     <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> 
    </body> 
</html> 
をあなたはCSS-セレクタを修正する必要がその後

// Selectors: 
// element {} Elements can appear as many times as you need them per Document 
// .class {} Classes can appear as many times as you need them per Document 
// #id {} IDs can appear just once per Document 

.heading { 
    text-align: center; 
} 

#profile_heading h3 { 
    text-align: center 
} 

.profile_data { 
    text-align: center; 
} 

// There is no Element with the Class "profile" 
/* 
.profile { 
    border-style: solid; 
    border-width: 5px; 
} 
*/ 

// There is no Element inside of the h3 with the Class "profile" 
/* 
h3. profile { 
    text-align: center; 
} 
*/ 

// There is no Element with ID "profile_content" 
/* 
#profile_content .profile { 
    text-align: center; 
} 
*/ 

しかし、最初:https://www.google.ch/?gfe_rd=cr&ei=6eISWYObOqLC8gfkzp3wBg#q=html+css+for+dummies

+0

ありがとうDinimer! –

+0

ええ、私はダミーの笑っていることを知っている! –

1

まず、きちんと自分のHTML:今

<div class="profile_content"> 
    <div id="profile_heading"> 
     <h3>Profiles</h3> 
    </div> 
    ...Your SQL Stuff... 
</div> 

あなたはよ、あなたのH3を中心にします必要:

.profile_content h3 
{ 
    text-align:center; 
} 

現在のCSSは、いくつかの点で正しくありません。「h3。 (H3ドット?どの要素のプロファイルが "もありません)。あなたはまた、存在しない『#profile_content』を参照しても意味がありませんプロファイル」。

1
<!DOCTYPE html> 
<html> 

<head> 
    <title><?php echo $title; ?></title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="<?php echo base_url();?>/css/bootstrap.min.css"> 

はトップで上記のコードを追加します。 PHPファイルのとの.phpとして代わりに.htmlを

関連する問題