2

I have a question concerning the Bootstrap grid layout and empty div's.

I have text and a button and i want the text and the button to show up in the middle (Horizontally) of the page. I have used empty div's to achieve this.

Is there a better way to do this. I don't want my text to be right aligned, because the text will be in two rows.

What is the best way to do this? Do people just use empty div's?

Thanks in advance

<div class="row">
        <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12"></div>
        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <span>
                This is a new feature 
                </br> for the site.
            </span>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                <a class="btn btn-default size" href="">Click button</a>
        </div>
        <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12"></div>
    </div>
Kong
  • 315
  • 2
  • 12

5 Answers5

4

If you not use text align center. You can use bootstrap class col-md-offset-3

Ankit Virani
  • 125
  • 1
  • 13
  • United with text-center, I believe this is the proper answer. Learn more about in http://getbootstrap.com/css/#grid-offsetting – teefars Mar 02 '16 at 00:05
1

If you want to center all your content in the row, just simply add text-center to your row and give your div's inside class="col-xs-12".

<div class="row text-center">
  <div class="col-xs-12">
    <span>
      This is a new feature for the site.
    </span>
  </div>
  <div class="col-xs-12">
    <a class="btn btn-default size" href="">Click button</a>
  </div>
</div>

JSFiddle

Tricky12
  • 6,752
  • 1
  • 27
  • 35
0

Use the text-center class for the div containing the text and button.

Update: I've done a quick search and found related posts. I'd recommend searching before asking, as your question might get down-voted and/or put on hold.

Community
  • 1
  • 1
Kody
  • 905
  • 9
  • 19
0

how about something simple like this - https://jsfiddle.net/8cuyc32z/1/ ?

HTML

<div class="text-center">
  <div class="tc-text">
    This is a new feature <br />for the site.
  </div>
  <div class="tc-btn">
    <a class="btn btn-default size" href="">Click button</a>
  </div>
</div>

CSS

.tc-text, .tc-btn {
  display:inline-block;
  vertical-align:middle;
  margin:0 10px;
}

hope that helps!

Saeed Salam
  • 467
  • 3
  • 8
0

The way Tricky12 described is to center all content in the column is that what you are trying to do? If so that method is correct.