[英]Is it possible to define a class based on a php variable
我想根據變量將身體定義為某種顏色。
我一直在嘗試這種影響。
<?php
$seperate_sitting_yes = "Yes";
if($seperate_sitting_yes == "Yes")
{
?>
<style type="text/css"></style>
body {
background-color: blue;
}
</style>
<?
}
?>
有沒有辦法做到這一點。 我想你可以用這種方式使用 HTML,也許你可以定義這樣的樣式......
任何想法...謝謝。
在您未編輯的問題中,您的</style>
太多了,只需刪除</style>
標簽即可!
<?php
$seperate_sitting_yes = "Yes";
if($seperate_sitting_yes == "Yes")
{
?>
<style type="text/css">
body {
background-color: blue;
}
</style>
<?php
}
?>
這是一種方法
<?php $seperate_sitting_yes = 'Yes'; ?>
<style type="text/css">
body {
background-color: <?= $seperate_sitting_yes == "Yes" ? "blue" : ""; ?>;
}
</style>
或者
<?php $seperate_sitting_yes = 'Yes'; ?>
<?php if($seperate_sitting_yes == "Yes") : ?>
<style type="text/css">
body {
background-color: "blue";
}
</style>
<?php endif ?>
或者
<?php $seperate_sitting_yes = 'Yes';
if($seperate_sitting_yes == 'Yes'){
echo '<style type="text/css"> body {background-color: "blue";}</style>';
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.