[英]Need help styling PHP in HTML
This is my PHP coding from which I am grabbing data from my DB with a select where statement and outputting it. 这是我的PHP编码,我使用select where语句从数据库中获取数据并将其输出。 I am trying to change the text properties such as font, colour and size on the print statement can anybody assis with how to do this?
我正在尝试更改打印语句上的文本属性,例如字体,颜色和大小,任何人都可以通过该方法来实现吗?
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
print " - Name: " . $row["fname"]. " " . $row["sname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
You can style lists using HTML <ul>
and <li>
elements. 您可以使用HTML
<ul>
和<li>
元素设置列表样式。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Stylists</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo "<ul>";
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<li>Name: " . $row["fname"]. " " . $row["sname"]. "</li>";
}
echo "</ul>";
} else {
echo "0 results";
}
mysqli_close($conn);
?></body>
</html>
And in css/style.css
put something like this: 然后在
css/style.css
以下内容:
li {
color: red;
font-weight: bold;
font-size: 12pt;
}
You can also put the style inline in the head section: 您还可以将样式内联在标题部分:
<style type="text/css">
li {
color: red;
font-weight: bold;
font-size: 12pt;
}
</style>
You can output your markdown like this: 您可以这样输出markdown:
print "<div class = 'sampleclass'> - Name: " . $row["fname"]. " " .
Then style it by including the below in an attached css
file 然后通过将以下内容包含在附加的
css
文件中来设置样式
.sampleclass {
font-size: 15px;
}
This is only about HTML and CSS, you could output directly your strings in HTML tags with echo. 这仅涉及HTML和CSS,您可以直接在带有echo的HTML标签中输出字符串。 The script needs to be encapsulated into the HTML's body and a pre-defined CSS classes for styling:
该脚本需要封装到HTML主体中,并需要预定义样式的CSS类:
<!doctype html>
<html>
<head>
....
<style type="text/css">
.redBold {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<?php
....
echo '<span class="redBold">This text is red and bold</span>';
?>
</body>
</html>
Of course you can also use inline styling: 当然,您也可以使用内联样式:
<span style="color: red; font-weight: bold;">Also this works</span>
You can always use CSS file and define the values. 您始终可以使用CSS文件并定义值。 For example:
例如:
body {
font-family: arial;
font-size: 15px;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
php txt
</body>
</html>
Also, you can use <span>
tags and style them. 另外,您可以使用
<span>
标记并设置其样式。 For example print this span using 'print' of php: 例如,使用php的'print'打印此范围:
<span style="font-family: arial; font-size: 15px;">text</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.