5

I'm using bootstrap and creating a panel. I'm trying to center my panel in the middle of the screen. It's inside a container.

<div class="container body-content">
    <div class="panel panel-default col-md-6">
        <div class="panel-title text-center">Log in</div>
        <div class="panel-body text-center">
             <h6>Use a local account to log in.</h6> 
        </div>
    </div>
</div>
Josh Crozier
  • 219,308
  • 53
  • 366
  • 287
user1186050
  • 12,296
  • 22
  • 123
  • 274

2 Answers2

14

Here is one approach:

Example Here

.container .panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
}

If you're interested in other approaches, see this answer.

Community
  • 1
  • 1
Josh Crozier
  • 219,308
  • 53
  • 366
  • 287
2

For others, like me, who came here looking to center panel only horizontally and not vertically, col-xx-offset is a quick way to center a panel horizontally.

<div class="panel panel-default col-md-6 col-md-offset-3">

See this answer

Anupam
  • 13,804
  • 17
  • 61
  • 90