1

<div class="container">
  <div class="row">
    <div class="col-md-4 col-md-offset-4">
      <button type="button" class="btn btn-outline-primary">Gallary</button>
    </div>
  </div>
</div>

I'm new to html and bootstrap. I'm trying to place a button in the center of the webpage vertically and horizontally. I have created a container and added a row inside it. Inside the row I offsetted a 4 column div element. Inside the div element is the button. But this button does'nt seem to be in the center. If I add a second button and tried offsetting it, it would be placed in the center but the hover wont work(or button does'nt work).

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
Kiran George
  • 63
  • 1
  • 1
  • 7

3 Answers3

2

In Bootstrap 4 you should use the text-center class to align inline-blocks.

NOTE: text-align:center; defined in a custom class you apply to your parent element will work regardless of the Bootstrap version you are using. And that's exactly what .text-center applies.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">    
<div class="container">
  <div class="row">
    <div class="col text-center">
      <button class="btn btn-default">Centered button</button>
    </div>
  </div>
</div>
Jeroen Heier
  • 3,520
  • 15
  • 31
  • 32
Fateme Ngh
  • 21
  • 1
0

As described in the official Bootstrap Docs, you can just add the class name text-center to a parent class list to horizontally center it's children text elements using text-align: center.


Check and run the following Code Snippet for a practical example of using the text-center class name:

/* CSS */

a {text-decoration: none;}
<!-- HTML -->

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
  <div class="row">

    <div class="col-md-4 col-md-offset-4 text-center">
        <button type="button" class="btn btn-outline-primary"><a href="#linkToYourOtherPage">Gallary</a></button>
    </div>

  </div>
</div>
AndrewL64
  • 15,794
  • 8
  • 47
  • 79
0

There is a class 'text-center' already with the property of text-align: center in bootstrap. You should use that in the parent element in order to center align child elements.

<div class="container">
  <div class="row">
    <div class="col-md-4 col-md-offset-4 text-center">
      <button class="btn btn-default">Gallery</button>
    </div>
  </div>
</div>
Yash009
  • 523
  • 4
  • 18