经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » Bootstrap » 查看文章
Bootstrap 实现表格样式、表单布局的实例代码
来源:jb51  时间:2018/12/10 9:19:46  对本文有异议

1. 表格的一些样式

举例:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>My Test bootstrap</title>
  6. <link rel="stylesheet" href="./css/bootstrap.min.css">
  7. <script type="text/javascript" src="./js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <table class="table table-striped">
  11. <caption>这是一个测试表格</caption>
  12. <thead>
  13. <tr>
  14. <th>姓名</th>
  15. <th>年龄</th>
  16. <th>地区</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td>小胡子</td>
  22. <td>26</td>
  23. <td>陕西</td>
  24. </tr>
  25. <tr>
  26. <td>大胡子</td>
  27. <td>26</td>
  28. <td>北京</td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </body>
  33. </html>

页面效果:

2. 表格行或单元格的样式

举例:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>My Test bootstrap</title>
  6. <link rel="stylesheet" href="./css/bootstrap.min.css">
  7. <script type="text/javascript" src="./js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <table class="table table-striped">
  11. <caption>这是一个测试表格</caption>
  12. <thead>
  13. <tr>
  14. <th>姓名</th>
  15. <th>年龄</th>
  16. <th>地区</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr class="info">
  21. <td>小胡子</td>
  22. <td>26</td>
  23. <td>陕西</td>
  24. </tr>
  25. <tr class="warning">
  26. <td>大胡子</td>
  27. <td>26</td>
  28. <td>北京</td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </body>
  33. </html>

页面效果:

3. 表单布局

(1)垂直表单:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>My Test bootstrap</title>
  6. <link rel="stylesheet" href="./css/bootstrap.min.css">
  7. <script type="text/javascript" src="./js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <form role="form">
  11. <div class="form-group">
  12. <label for="name">姓名</label>
  13. <input type="text" class="form-control" id="name" placeholder="请输入姓名">
  14. </div>
  15. <div class="form-group">
  16. <label for="inputfile">选择文件</label>
  17. <input type="file" id="inputfile">
  18. </div>
  19. <button type="submit" class="btn btn-default">提交</button>
  20. </form>
  21. </body>
  22. </html>

效果:

(2)内联表单:它的所有元素是内联的,向左对齐的,标签是并排的

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>My Test bootstrap</title>
  6. <link rel="stylesheet" href="./css/bootstrap.min.css">
  7. <script type="text/javascript" src="./js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <form role="form" class="form-inline">
  11. <div class="form-group">
  12. <label for="name">姓名</label>
  13. <input type="text" class="form-control" id="name" placeholder="请输入姓名">
  14. </div>
  15. <div class="form-group">
  16. <label for="inputfile">选择文件</label>
  17. <input type="file" id="inputfile">
  18. </div>
  19. <button type="submit" class="btn btn-default">提交</button>
  20. </form>
  21. </body>
  22. </html>

效果:

(3)水平表单:水平表单与其他表单不仅标记的数量上不同,而且表单的呈现形式也不同

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <title>My Test bootstrap</title>
  6. <link rel="stylesheet" href="./css/bootstrap.min.css">
  7. <script type="text/javascript" src="./js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <form role="form" class="form-horizontal">
  11. <div class="form-group">
  12. <label for="name" class="col-sm-2 control-label">姓名</label>
  13. <div class="col-sm-10">
  14. <input type="text" class="form-control" id="name" placeholder="请输入姓名">
  15. </div>
  16. </div>
  17. <div class="form-group">
  18. <label for="inputfile" class="col-sm-2 control-label">选择文件</label>
  19. <div class="col-sm-10">
  20. <input type="file" id="inputfile">
  21. <div>
  22. </div>
  23. <div class="form-group">
  24. <div class="col-sm-12">
  25. <button type="submit" class="btn btn-default">提交</button>
  26. </div>
  27. </div>
  28. </form>
  29. </body>
  30. </html>

效果:

总结

以上所述是小编给大家介绍的Bootstrap 实现表格样式、表单布局的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对w3xue网站的支持!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号