+ 3
How can I write a block of code that would be displayed on the output?
I want to display a piece of code in the output. But when I try to put the piece of code in <code>..... </code> tag, it is displaying the code after executing it. I want to do it just like comments, the code should not be executed but it should be displayed in the output. How can I do so?
6 ответов
+ 3
Can you post your code here?
+ 3
I'm not using PHP.
Only HTML & CSS
+ 2
Use this tool to build an escaped version of your code
https://www.freeformatter.com/html-escape.html
Then drop it in between the <code> tags. You can style it like this to give it a nice Box around the code
.codebox {
/* Below are styles for the codebox (not the code itself) */
border: 1px solid black;
background-color: #f0f0f5;
width: 100%;
overflow: auto;
padding: 10px;
}
example
<div class="codebox">
<code><article class="panel" id="page2"></code>
</div>
+ 1
Try using <pre></pre> tags. I’ve never tried, but it may work
+ 1
The <code> just styles what is inside it. Meaning it will still render any HTML inside.
Read this:
https://stackoverflow.com/questions/18131084/html-code-tags-no-execute?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
If you're using PHP convert code using htmlspecialchars().
See my example here:
https://code.sololearn.com/WeiSobPicPCe/?ref=app
PHP example of <code> tags here:
https://code.sololearn.com/wEXoh23I2Lvk/?ref=app
+ 1
Abhishek Ram Well then use <b> method for escaping your HTML. <b> is what <b> looks like escaped.
Use this website to escape the HTML for you, then put the result I'm between the <code> tags.