Bootstrap center heading

后端 未结 5 1096
后悔当初
后悔当初 2020-12-13 05:26

It is my first Twitter Bootstrap experience. I have added some headings (h1, h2, etc.) and they are aligned by left side. What is the right way to center headings?

相关标签:
5条回答
  • 2020-12-13 05:49
    .text-left {
      text-align: left;
    }
    
    .text-right {
      text-align: right;
    }
    
    .text-center {
      text-align: center;
    }
    

    bootstrap has added three css classes for text align.

    0 讨论(0)
  • 2020-12-13 05:50

    just use class='text-center' in element for center heading.

    <h2 class="text-center">sample center heading</h2>
    

    use class='text-left' in element for left heading, and use class='text-right' in element for right heading.

    0 讨论(0)
  • 2020-12-13 05:56

    Bootstrap comes with many pre-build classes and one of them is class="text-left". Please call this class whenever needed. :-)

    0 讨论(0)
  • 2020-12-13 06:03

    Just use "justify-content-center" in the row's class attribute.

    <div class="container">
      <div class="row justify-content-center">
        <h1>This is a header</h1>
      </div>
    </div>
    
    0 讨论(0)
  • 2020-12-13 06:03

    Per your comments, to center all headings all you have to do is add text-align:center to all of them at the same time, like so:

    CSS

        h1, h2, h3, h4, h5, h6 {
            text-align: center;
        }
    
    0 讨论(0)
提交回复
热议问题