我正在尝试使用bootstrap,这是我写的代码:
<!doctype html> <html lang="en"> <head> <Meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="./css/bootstrap.min.css"> <link rel="stylesheet" href="./css/bootstrap-theme.min.css"> <style type="text/css"> .row-centered { text-align:center; } .col-centered { display:inline-block; float:none; text-align:left; margin-right:-4px; } .pos{ position: relative; top: 240px; } </style> </head> <body> <div class="container"> <div class="row row-centered pos"> <div class="col-lg-8 col-centered"> <div class="well"></div> </div> <div class="col-lg-8 col-centered"> <div class="well"></div> </div> <div class="col-lg-8 col-centered"> <div class="well"></div> </div> </div> </div> </body> </html>
输出如屏幕截图所示:
但是当我转换为手机屏幕时,我会这样:
我希望div在移动屏幕中显示在中心,一个在一个以上.我该怎么做?
但它没有响应.
解决方法
你可以在你的div中使用col-xs-12,将它添加到每个div中它会像你期望的那样工作
<body> <div class="container"> <div class="row row-centered pos"> <div class="col-lg-8 col-xs-12 col-centered"> <div class="well"></div> </div> <div class="col-lg-8 col-xs-12 col-centered"> <div class="well"></div> </div> <div class="col-lg-8 col-xs-12 col-centered"> <div class="well"></div> </div> </div> </div> </body>
有关bootstrap grid option的更多信息