locked
How to Center 3 columns in Bootstrap RRS feed

  • Question

  • User248267340 posted

    I'd like to display three (3) squares on a page, centered, using bootstrap 4.3.1.

    Wouldn't it be great if bootstrap allowed something like:

    <div class="row">
       <div class="col-1.5"></div>
       <div class="col-3">Box 1</div>
       <div class="col-3">Box 2</div>
       <div class="col-3">Box 3</div>
       <div class="col-1.5">Box 1</div>
    </div>

    Should I just code the display outside of bootstrap, or is there a way to use bootstrap?

    Maybe take time and learn offset? Or is there some other trick?

    I'd be grateful for any tips!

    Friday, September 11, 2020 3:46 PM

Answers

  • User-474980206 posted

    or use bootstrap 4 

      <div class="content">
         <div class="row justify-content-center">
            <div class="col-3 m-1">Box 1</div>
            <div class="col-3 m-1">Box 2</div>
            <div class="col-3 m-1">Box 3</div>
         </div>
      </div>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 11, 2020 6:41 PM

All replies

  • User475983607 posted

    Use CSS.

    <div class="container">
        <div class="row" style="width:80%;margin:auto;">
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
        </div>
    </div>

    Or

    <div class="container" style="width:80%;margin:auto;">
        <div class="row">
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
            <div class="col col-lg-4" style="background-color:gainsboro">
                One of three columns
            </div>
        </div>
    </div>

    Friday, September 11, 2020 4:37 PM
  • User248267340 posted

    mgebhard,

    Thank you very much! The code you gave me works great.

    How can I include margins so the columns look like separated boxes? I tried putting in margins but the 3rd box wrapped around.

    Friday, September 11, 2020 6:28 PM
  • User-474980206 posted

    or use bootstrap 4 

      <div class="content">
         <div class="row justify-content-center">
            <div class="col-3 m-1">Box 1</div>
            <div class="col-3 m-1">Box 2</div>
            <div class="col-3 m-1">Box 3</div>
         </div>
      </div>
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 11, 2020 6:41 PM
  • User248267340 posted

    Bruce,

    You are gold. I put in some code that mgebhard suggested, and got everything perfect.

    Thank you, both of you!

    Friday, September 11, 2020 7:14 PM