Ich benutze PHP, um Daten aus MySQL anzuzeigen. Hier sind meine CSS-Statements:
<style type=”text/css”>
table {
margin: 8px;
}
th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}
td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>
Sie werden für die Anzeige von table, tableheader, tabledate ..__ verwendet. Ich bin neu in php css, also frage ich mich nur, wie man den obigen css-Stil in PHP-Codes verwendet:
<?php>
echo "<table>";
echo "<tr><th>ID</th><th>hashtag</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td> <td>$row[1]</td></tr>\n";
}
echo "</table>";
<?>
Cascading Style Sheets (CSS) ist eine Stylesheet-Sprache, in der die Präsentationssemantik (das Aussehen und die Formatierung) eines Dokuments beschrieben wird, das in einer Auszeichnungssprache geschrieben ist Weitere Informationen: http://en.wikipedia.org/ wiki/Cascading_Style_Sheets CSS ist keine Programmiersprache und verfügt nicht über die Tools, die mit einer serverseitigen Sprache wie PHP geliefert werden. Wir können jedoch serverseitige Sprachen verwenden, um Stylesheets zu generieren.
<html>
<head>
<title>...</title>
<style type="text/css">
table {
margin: 8px;
}
th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}
td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>
</head>
<body>
<?php>
echo "<table>";
echo "<tr><th>ID</th><th>hashtag</th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td> <td>$row[1]</td></tr>\n";
}
echo "</table>";
?>
</body>
</html>
Ich denke, Sie haben Ihren CSS-Code in einer Datenbank und möchten eine PHP-Datei als CSS rendern. Wenn das der Fall ist...
In Ihrer html-Seite :
<html>
<head>
<!- head elements (Meta, title, etc) -->
<!-- Link your php/css file -->
<link rel="stylesheet" href="style.php" media="screen">
<head>
Dann innerhalb von style.php file:
<?php
/*** set the content type header ***/
/*** Without this header, it wont work ***/
header("Content-type: text/css");
$font_family = 'Arial, Helvetica, sans-serif';
$font_size = '0.7em';
$border = '1px solid';
?>
table {
margin: 8px;
}
th {
font-family: <?=$font_family?>;
font-size: <?=$font_size?>;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: <?=$border?> #000;
}
td {
font-family: <?=$font_family?>;
font-size: <?=$font_size?>;
border: <?=$border?> #DDD;
}
Habe Spaß!
Setzen Sie das CSS einfach außerhalb des PHP - Tags. Hier:
<html>
<head>
<title>Title</title>
<style type="text/css">
table {
margin: 8px;
}
</style>
</head>
<body>
<table>
<tr><th>ID</th><th>hashtag</th></tr>
<?php
while($row = mysql_fetch_row($result))
{
echo "<tr onmouseover=\"hilite(this)\" onmouseout=\"lowlite(this)\"><td>$row[0]</td> <td>$row[1]</td></tr>\n";
}
?>
</table>
</body>
</html>
Beachten Sie, dass die Tags PHP <?php
und ?>
sind.
Ich habe dies Im new to php css
nicht verstanden, aber da Sie Ihr CSS auf Elementebene definiert haben, werden Ihre Stile bereits auf Ihren PHP - Code angewendet
Ihr PHP Code soll mit HTML wie folgt verwendet werden
<!DOCTYPE html>
<html>
<head>
<style>
/* Styles Go Here */
</style>
</head>
<body>
<?php
echo 'Whatever';
?>
</body>
</html>
Denken Sie auch daran, dass Sie HTML nicht mit php nachstellen mussten, sondern einfach auf diese Weise trennen
<table>
<tr>
<td><?php echo 'Blah'; ?></td>
</tr>
</table>
Versuchen Sie, Ihren PHP-Code in ein HTML-Dokument einzufügen:
Hinweis: Ihre Datei wird nicht als index.html gespeichert, aber als index.php oder Ihr PHP wird nicht funktionieren!
//dont inline your style
<link rel="stylesheet" type="text/css" href="mystyle.css"> //<--this is the proper way!
//save a separate style sheet (i.e. cascading style sheet aka: css)
css :hover
ist irgendwie wie js onmouseover
row1 {
// your css
}
row1:hover {
color: red;
}
row1:hover #a, .b, .c:nth-child[3] {
border: 1px solid red;
}
nicht ganz sicher, wie es funktioniert, aber css wendet Stile auf Echo-IDs an
Die absolut einfachste Möglichkeit (mit Ihrem aktuellen Code) besteht darin, Ihrem PHP-Code eine require_once("path/to/file")
-Anweisung hinzuzufügen.
<?php
require_once("../myCSSfile.css");
echo "<table>";
...
Nebenbei bemerkt: Das <?php
-Start-Tag hat am Ende keinen >
, und das schließende ?>
php-Tag beginnt nicht mit <
. Komisch, aber wahr.