It's probably stupid question, but I can not find an answer. How can I style echo output with css? I have this code:
echo "<div id="errormsg"> Error </div>";
Now it displays syntax error, I think because of those quotes around errormsg. I've tried single quotes, but with no effect. Thank you
When outputting HTML, it's easier to use single quotes so you can use proper double quotes inside like so:
echo '<div id="errormsg"> Error </div>';
That will get rid of your parse error... To edit the style you will need to use CSS with the selector of #errormsg
like so:
#errormsg {
color: red;
}
try
echo "<div id=\"errormsg\"> Error </div>";
First you need to either use single-quotes to surround the attribute value:
echo "<div id='errormsg'> Error </div>";
Or you could reverse that, to give:
echo '<div id="errormsg"> Error </div>';
Or you should escape the quotes:
echo "<div id=\"errormsg\"> Error </div>";
And then style the resulting element with the CSS:
#errormsg {
/* css */
}
The syntax problem you were encountering is a result of terminating the string and then having a disparate element between the first and second strings, with which PHP has no idea what to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With