前端之bootstrap框架

一、介绍

  Bootstrap 是最受欢迎的 HTML、CSS 和 JS 框架,用于开发响应式布局、移动设备优先的 WEB 项目。

二、引入方式

  地址:https://v3.bootcss.com/
  bootstrap需要依赖于jQuery才能正常执行(动态效果)
  第一次使用该框架的时候最好采用本地导入的方式,让pycharm记住bootstrap的关键字。

  1、本地引入

1.引入jQuery
2.引入bootstrap的css文件
3.引入bootstrap的js文件

将下载好的bootstrap文件夹拖到pycharm项目中即可,再按上面的方式引入

  2、CDN引入

1.引入jQuery CDN
2.引入bootstrap css的 CDN
3.引入bootstrap js的 CDN

 

三、页面布局

  1、多数浏览页面的左右两侧都有空白区域————称谓左右留白

container    左右留白
container-fluid   左右不留白

 

  2、栅格系统

    Bootstrap 提供了一套响应式、移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列,即响应式布局
              该系统能够自动监测浏览器窗口大小,从而根据大小来进行变化。

row            行  # 一个row就是一行 一行是固定的12份,一个row里面还可以无限的嵌套row
col-md-1     占几份
col-sm-1     占几份
col-xs-1      占几份
col-lg-1       占几份

代码实例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <style>
      .c1{
          background-color: palevioletred;
          height: 200px;
          border: 5px solid black;
      }
    </style>


</head>
<body>
    <div class="container">
      <div class="row"></div>
        <div class="col-lg-6 c1"></div>       将六份分一边
        <div class="col-lg-6 c1"></div>
    </div>
</body>
</html>

注意上面是在网页端的参数,如果改到移动端则需要添加代码:

<div class="col-lg-6 c1 col-sm-5"></div>
<div class="col-lg-6 c1 col-sm-7"></div>
我这里将移动端页面改为5、7分成。这样在pc端为6,6分。在移动端为5,7分

栅格系统参数

 

  3、列偏移

    就是将任意份数的一行,进行向左或向右移动的操作。

<body>
    <div class="container">
      <div class="row"></div>
        <div class="col-lg-8 c1 col-lg-offset-2"></div>
    </div>
</body>

在基于总的12份的基础上。代表只需要8列,然后向右移动2分就居中了

 

  4、表格与表单

  表格:

    为任意 <table> 标签添加 .table 类可以为其赋予基本的样式 — 少量的内补(padding)和水平方向的分隔线。

语法:
<table class="table">
  ...
</table>

    表格颜色设置参数

 

代码演示:一般都要给表格加上样式所以设定这几个参数:<table class="table table-hover table-bordered table-striped">

  table-bordered:带边框的表格样式

  table-hover:鼠标悬停

  table-striped:有条纹的

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <style>
      .c1{
          background-color: palevioletred;
          height: 200px;
          border: 5px solid black;
      }
    </style>


</head>
<body>
    <div class="container">
        <div class="row">
<!--            向右移动3份,居中-->
            <div class="col-md-6 col-md-offset-3">
<!--                文本直接text-center即可。-->
                <h2 class="text-center">表单</h2>
<!--                添加表格的样式,用着三个即可。可以全部加上更好看-->
                <table class="table table-hover table-bordered table-striped">
                    <thead>
                        <tr class="active">
                            <th>ID</th>
                            <th>Name</th>
                            <th>颜色显示行</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="success">
                            <td>1</td>
                            <td>张三</td>
                            <td>class="success"</td>
                        </tr>
                    </tbody>
                    <tbody>
                        <tr class="info">
                            <td>2</td>
                            <td>李四</td>
                            <td>class="info"</td>
                        </tr>
                    </tbody>
                    <tbody>
                        <tr class="warning">
                            <td>3</td>
                            <td>王麻五</td>
                            <td>class="warning"</td>
                        </tr>
                    </tbody>
                    <tbody>
                        <tr class="danger">
                            <td>4</td>
                            <td>老六</td>
                            <td>class="danger"</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>

 

  表单:form

    基本设置:想让input框有样式,加入class=‘from-control’即可。

<input type="text" class="form-control"  disabled>
form-control 优化页面
disbaled 禁止其与用户有任何交互

代码演示:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
    <form class="form-inline" method="" action="">
      <div class="form-group">
    <label class="sr-only" for="exampleInputEmail3">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail3" placeholder="Email">
  </div>
  <div class="form-group">
    <label class="sr-only" for="exampleInputPassword3">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword3" placeholder="Password">
  </div>
  <div class="checkbox">
    <label>
      <input type="checkbox"> Remember me
    </label>
  </div>
  <button type="submit" class="btn btn-default">Sign in</button>
</form>
</body>
</html>    

 

  5、按钮:

    提交的按钮,跳转页面的按钮等,设置一些样式和属性。

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>



</head>
<body>
<!-- Standard button -->
<button type="button" class="btn btn-default">(默认样式)Default</button>

<!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
<button type="button" class="btn btn-primary">(首选项)Primary</button>

<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success">(成功)Success</button>

<!-- Contextual button for informational alert messages -->
<button type="button" class="btn btn-info">(一般信息)Info</button>

<!-- Indicates caution should be taken with this action -->
<button type="button" class="btn btn-warning">(警告)Warning</button>

<!-- Indicates a dangerous or potentially negative action -->
<button type="button" class="btn btn-danger">(危险)Danger</button>

<!-- Deemphasize a button by making it look like a link while maintaining button behavior -->
<button type="button" class="btn btn-link">(链接)Link</button>
</body>
</html>

    链接a标签添加形状

<a href="#" class="btn btn-primary btn-lg active" role="button">Primary link</a>
<a href="#" class="btn btn-default btn-lg active" role="button">Link</a>

    改变图片形状

<img src="..." alt="..." class="img-rounded">
<img src="..." alt="..." class="img-circle">
<img src="..." alt="..." class="img-thumbnail">

    关闭按钮

<button type="button" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button>

    快速浮动

<div class="pull-left">...</div>
<div class="pull-right">...</div>

    清除浮动

      通过为父元素添加 .clearfix 类可以很容易地清除浮动(float)。

<!-- Usage as a class -->
<div class="clearfix">...</div>

    让内容块居中

      为任意元素设置 display: block 属性并通过 margin 属性让其中的内容居中。

<div class="center-block">...</div>

// Class
.center-block {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

 

四、组件

  图标:直接复制用<span>标签包裹起来,在span标签里面写下组件图标的英文即可

 

五、导航条

  1、代码

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Brand</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
      <form class="navbar-form navbar-left">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
      </form>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

  2、表单

    将表单放置于 .navbar-form 之内可以呈现很好的垂直对齐,并在较窄的视口(viewport)中呈现折叠状态。使用对齐选项可以规定其在导航条上出现的位置。

<form class="navbar-form navbar-left" role="search">
  <div class="form-group">
    <input type="text" class="form-control" placeholder="Search">
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

  3、改变导航条颜色

      通过添加 .navbar-inverse 类可以改变导航条的外观。

<nav class="navbar navbar-inverse">

 

  4、分页

<nav aria-label="Page navigation">
  <ul class="pagination">
    <li>
      <a href="#" aria-label="Previous">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
    <li>
      <a href="#" aria-label="Next">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </ul>
</nav>

  5、巨幕

<div class="jumbotron">
  <h1>Hello, world!</h1>
  <p>...</p>
  <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
</div>

 

注意:更多的使用,请在官方文档查看!!!!!!!

 

实战管理系统

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="fontawesome/css/font-awesome.min.css">
</head>
<body>
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">图书管理系统</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">书籍 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">作者</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">更多查询 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">Separated link</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
            </ul>
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">Jason</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">更多操作 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">修改密码</a></li>
                        <li><a href="#">修改头像</a></li>
                        <li><a href="#">后台管理</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="#">注销</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<div class="container">
    <div class="row">
        <div class="col-md-3">
            <div class="list-group">
                <a href="#" class="list-group-item active">
                    书籍管理
                </a>
                <a href="#" class="list-group-item">作者管理</a>
                <a href="#" class="list-group-item">出版社管理</a>
                <a href="#" class="list-group-item">其他</a>
            </div>


        </div>
        <div class="col-md-9">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title">图书管理系统
                        <span class="glyphicon glyphicon-book pull-right"></span>
                    </h3>
                </div>
                <div class="panel-body">
                    <a href="" class="pull-right btn btn-success">新增</a>
                    <form class="form-inline">
                        <div class="form-group">
                            <div class="input-group">

                                <input type="text" class="form-control" id="exampleInputAmount" placeholder="搜索">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary">搜索</button>
                    </form>
                    <br>
                    <table class="table table-striped table-hover table-bordered">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>书名</th>
                            <th>价格</th>
                            <th>作者</th>
                            <th class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>1</td>
                            <td>哈哈哈哈书</td>
                            <td>199.99</td>
                            <td>哈哈哥</td>
                            <td class="text-center">
                                <a href="" class="btn btn-primary btn-sm">编辑</a>
                                <a href="" class="btn btn-danger btn-sm">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td>1</td>
                            <td>嘻嘻嘻嘻杂志</td>
                            <td>199.99</td>
                            <td>嘻嘻姐</td>
                            <td class="text-center">
                                <a href="" class="btn btn-primary btn-sm">编辑</a>
                                <a href="" class="btn btn-danger btn-sm">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td>1</td>
                            <td>哒哒哒哒哒本子</td>
                            <td>199.99</td>
                            <td>哒哒哒</td>
                            <td class="text-center">
                                <a href="" class="btn btn-primary btn-sm">编辑</a>
                                <a href="" class="btn btn-danger btn-sm">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td>1</td>
                            <td>嘟嘟嘟嘟玩具车义</td>
                            <td>199.99</td>
                            <td>嘟嘟嘟嘟</td>
                            <td class="text-center">
                                <a href="" class="btn btn-primary btn-sm">编辑</a>
                                <a href="" class="btn btn-danger btn-sm">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td>1</td>
                            <td>三国演义</td>
                            <td>199.99</td>
                            <td>罗贯中</td>
                            <td class="text-center">
                                <a href="" class="btn btn-primary btn-sm">编辑</a>
                                <a href="" class="btn btn-danger btn-sm">删除</a>
                            </td>
                        </tr>

                        </tbody>
                    </table>


                    <div class="text-center">
                        <nav aria-label="Page navigation">
                        <ul class="pagination">
                            <li>
                                <a href="#" aria-label="Previous">
                                    <span aria-hidden="true">«</span>
                                </a>
                            </li>
                            <li><a href="#">1</a></li>
                            <li><a href="#">2</a></li>
                            <li><a href="#">3</a></li>
                            <li><a href="#">4</a></li>
                            <li><a href="#">5</a></li>
                            <li>
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">»</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                    </div>
                </div><!-- /input-group -->


            </div>
        </div>


    </div>

</div>
</div>


</body>
</html>
</body>
</html>

 

posted @ 2022-04-03 17:01  新入世界的小白  阅读(2066)  评论(0编辑  收藏  举报