Horizontally and vertically center a pre tag without the use of tables?

后端 未结 3 1891
天命终不由人
天命终不由人 2020-12-20 04:12

Is it possible to horizontally and vertically align a pre tag without tables? I want to vertically and horizontally align some ASCII art on a webpage. While I have already p

相关标签:
3条回答
  • 2020-12-20 04:32

    Throw er in a div and center that div one of these ways http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/

    0 讨论(0)
  • 2020-12-20 04:33

    The <pre> tag treats every space as a non-breaking space, i.e.

    &nbsp;

    and won't automatically remove whitespace. So, you can pad the right side of each line in your ASCII art. If every line in the ASCII art contains exactly the same number of characters (including spaces) you can use

    pre {text-align: center;}
    

    as Catfish suggested and they'll all line up together.

    0 讨论(0)
  • 2020-12-20 04:54

    the PRE element is a block element by default, so it is the same as centering a div or a paragraph or an h1 or h2 element. You need to use display: table and display: table-cell.

    My answer here should help solve your problem... and the fiddle found here: http://jsfiddle.net/dcGZm/13/

    The old center a image in a div issue ( image size variable - div size fixed )

    0 讨论(0)
提交回复
热议问题