I’m beginning to do HTML, CSS and PHP and I can’t have a clear cut answer on how to add CSS to my existing PHP file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style_conjugate.php" media="screen" />
</head>
<body>
<?php
$arr verbs = [
verbs
];
$arr base verbs= [
base verbs
];
for ($i = 0; $i < $max.baseverbs; $i++)
{
foreach (verbs as pronoun => conjugation)
{
echo
}
echo for linebreak
}
?>
</body>
</html>
I would like the verbs to be displayed in blue, which needs tobe done in PHP, according to what I have read, however I can’t get it to work.
I can’t seem to specify how the colour should be changed in the php script`:
php.conjugation
{
blue color
}
Any help would be greatly appreciated.
Advertisement
Answer
You are specifying your CSS file to be a “text/css”, however you are linking to a .php
file.
You need to firstly create a new stylesheet (CSS File) with the .css
extension.
Create a file called style.css
in your directory and link it into your PHP file with the following:
<link rel="stylesheet" type="text/css" href="style.css" />
The contents of your stylesheet should contain the following class which you can use to get blue text:
style.css:
.text-blue {
color: blue;
}
Now you can use this CSS class in your PHP echo
to apply the color blue on the $conjugation
variable:
foreach ($arr_pronoun_to_conjugation as $pronoun => $conjugation)
{
echo "$pronoun " . $arr_verbstem[$i] . " <div class='text-blue'>$conjugation</div><br>";
}