How to center a div with Bootstrap2?

前端 未结 9 1129
星月不相逢
星月不相逢 2020-12-04 09:16

http://twitter.github.com/bootstrap/scaffolding.html

I tried like all combinations:

b
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 10:07

    Bootstrap's spans are floated to the left. All it takes to center them is override this behavior. I do this by adding this to my stylesheet:

    .center {
         float: none;
         margin-left: auto;
         margin-right: auto;
    }
    

    If you have this class defined, just add it to the span and you're good to go.

    box

    Note that this custom center class must be defined after the bootstrap css. You could use !important but that isn't recommended.

提交回复
热议问题