我有一个表单,允许用户更改他们所在网站的样式。我尝试将样式表保存为PHP文件,但现在样式没有显示,事件虽然我将样式表链接更改为href =“styles.php”。如何让PHP样式表影响我的页面?这是样式表代码:
<?php include("session_start.php")?>
<?php
$sql = "SELECT * FROM styles WHERE user_name='$user_name'";
$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
?>
<?php
while($column = mysqli_fetch_assoc($result)){
?>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: <?php echo $column['background_color'] ?>;
color: <?php echo $column['text_color'] ?>;
font-size: <?php echo $column['body_size'] ?>;
}
h1,h2,h3,h4,h5,h6 {
color: <?php echo $column['header_color'] ?>;
}
h1 {
font-size: <?php echo $column['h1_size'] ?>;
}
h2 {
font-size: <?php echo $column['h2_size'] ?>;
}
h3 {
font-size: <?php echo $column['h3_size'] ?>;
}
h4 {
font-size: <?php echo $column['h4_size'] ?>;
}
h5 {
font-size: <?php echo $column['h5_size'] ?>;
}
h6 {
font-size: <?php echo $column['h6_size'] ?>;
}
.registration-form {
max-width: 300px;
margin: 100px auto;
}
.align-right {
text-align: right;
}
#post_content {
width: 100%;
height: 200px;
}
.view-post-content {
padding-top: 10px;
padding-bottom: 10px;
}
.category {
font-weight: bold;
}
hr {
border-top: 1px solid grey;
}
a:hover {
color: purple;
}
<?php
}
?>
答案 0 :(得分:0)
<style type="text/css">
<?php
while($column = mysqli_fetch_assoc($result)){
?>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: <?php echo $column['background_color'] ?>;
color: <?php echo $column['text_color'] ?>;
font-size: <?php echo $column['body_size'] ?>;
}
h1,h2,h3,h4,h5,h6 {
color: <?php echo $column['header_color'] ?>;
}
h1 {
font-size: <?php echo $column['h1_size'] ?>;
}
h2 {
font-size: <?php echo $column['h2_size'] ?>;
}
h3 {
font-size: <?php echo $column['h3_size'] ?>;
}
h4 {
font-size: <?php echo $column['h4_size'] ?>;
}
h5 {
font-size: <?php echo $column['h5_size'] ?>;
}
h6 {
font-size: <?php echo $column['h6_size'] ?>;
}
.registration-form {
max-width: 300px;
margin: 100px auto;
}
.align-right {
text-align: right;
}
#post_content {
width: 100%;
height: 200px;
}
.view-post-content {
padding-top: 10px;
padding-bottom: 10px;
}
.category {
font-weight: bold;
}
hr {
border-top: 1px solid grey;
}
a:hover {
color: purple;
}
<?php
} ?>
</style>
答案 1 :(得分:0)
创建一个php文件 将此代码添加到您的文件simple =&gt; style.php 标题(&#34; Content-Type:text / css; charset = utf-8&#34;); 并添加您的样式并将文件添加到您的页面样式