将Bootstrap中的任何元素居中
在Bootstrap中使用.center-block类将元素居中。
您可以尝试运行以下代码来实现.center-block类:
示例
<!DOCTYPE html> <html> <head> <title>Bootstrap Example</title> <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet"> <script src = "/scripts/jquery.min.js"></script> <script src = "/bootstrap/js/bootstrap.min.js"></script> </head> <body> <div class = "container"> <h1>Heading One</h1> <div class = "center-block" style = "background-color:green;color: white; width:200px;">Text will be in center.</div> </div> </body> </html>