Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用css样式更改php代码的字体_Php_Html_Css_Forms_Switch Statement - Fatal编程技术网

使用css样式更改php代码的字体

使用css样式更改php代码的字体,php,html,css,forms,switch-statement,Php,Html,Css,Forms,Switch Statement,守则: <!DOCTYPE html> <html> <head> <title>Greeting Service!</title> <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' /> <style type="text/css"> #name { fo

守则:

<!DOCTYPE html>
<html>
<head>
<title>Greeting Service!</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
<style type="text/css">
#name {
font-family: "Open Sans", sans-serif;
font-weight: 700;
}
#greet {
font-family: "Open Sans", sans-serif;
font-weight: 400;
}
</style>
</head>
<body>
<center>
<?php
if (isset($_POST['language'])) {
$language = $_POST['language'];
switch ($_POST['language']) {
case "option1":
$result = "Hello, {$_POST['name']}!"; 
break;
case "option2":
$result = "你好, {$_POST['name']}!"; 
break;
case "option3":
$result = "Bonjour, {$_POST['name']}!"; 
break;
}
echo $result;
} else {
?>
<form method="post" action="">
<h1 id="name">What's Your Name?</h1>
<input type="text" name="name" placeholder="Name Here" />
<h4 id="greet">Greet me in:
<select name="language">
<option value="option1">English</option>
<option value="option2">Chinese</option>
<option value="option3">French</option>
</select>
</h4>
<input type="submit" value="Greet Me!" />
</form>
</center>
<?php
}
?>
</body>
</html>

我不确定如何更改从文本框输出的“名称”的字体。可以在php代码中使用css样式吗?我想更改从文本框输出的文本的字体大小和字体系列。谢谢

是的,您可以像往常一样立即应用任何CSS样式:

$result = "<p style="font-weight:val;font-family:val;">Hello, {$_POST['name']}!</p>"; 

这就是所谓的CSS 101。问问你自己;网页开发人员也可以是网页设计师吗?;-反之亦然。将它放在元素中,然后按照其他元素的样式设置样式。在元素中,为它们赋予属性,然后设置样式。最好只将$result包装在元素中…这里是echo$result;。他/她可能希望在switch语句中对不同的情况应用不同的样式,但你可能是对的。我想,他/她也可以在switch语句中动态设置样式值或样式代码,并进行编辑
switch ($_POST['language']) {
case "option1":
$result = "Hello, {$_POST['name']}!"; 
$style = 'font-weight:val;font-family:val';
break;
case "option2":
$result = "你好, {$_POST['name']}!"; 
$style = 'font-weight:val;font-family:val';
break;
case "option3":
$result = "Bonjour, {$_POST['name']}!";
$style = 'font-weight:val;font-family:val';
break;
}
echo '<p style="' . $style . '">' . $result . '</p>';
<!DOCTYPE html>
<html>
<head>
    <title>Greeting Service!</title>
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css' />
    <style type="text/css">
        #name {
            font-family: "Open Sans", sans-serif;
            font-weight: 700;
            background-color: red;
        }
        #greet {
            font-family: "Open Sans", sans-serif;
            font-weight: 400;
        }
    </style>
</head>
<body>
    <center>
        <?php
        if (isset($_POST['language'])) {
        $language = $_POST['language'];
        switch ($_POST['language']) {
        case "option1":
        $result = "<p id=\"name\">Hello, {$_POST['name']}!</p>"; 
        break;
        case "option2":
        $result = "<p id=\"name\">你好, {$_POST['name']}!</p>"; 
        break;
        case "option3":
        $result = "<p id=\"name\">Bonjour, {$_POST['name']}!</p>"; 
        break;
        }
        echo $result;
        } else {
        ?>
            <form method="post" action="">
            <h1 id="name">What's Your Name?</h1>
            <input type="text" name="name" placeholder="Name Here" />
            <h4 id="greet">Greet me in:
                <select name="language">
                    <option value="option1">English</option>
                    <option value="option2">Chinese</option>
                    <option value="option3">French</option>
                </select>
            </h4>
            <input type="submit" value="Greet Me!" />
            </form>
        <?php
        }
        ?>
    </center>
</body>
</html>