How to center pre tag alignment in HTML

I am trying to post some code on a blog using a preliminary tag. Something like that:

void function(){return 0;}

Now I want all this code to be centered. I am talking not only about the text, but also about the border around it. Width is currently set to 60%. So I want all this to be centered. Is there any way to do this?

+3
source share
1 answer

Add your own CSS <div>class, which sets the font to courier(10pt) and has left and right margins set so that it is centered on the page.

.code {
  font-family:courier;
  font-size: 10pt;
  margin: 5px; border: 1px solid black;
} 

Then name it like this:

<div class="code">Your Code Here</div>

margin. 4 , , .

+3

Source: https://habr.com/ru/post/1707110/


All Articles