bootstrap学习-初步使用介绍

准备

下载Bootstrap

安装Bootstrap

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>页面标题</title>
  <!-- 引入Bootstrap核心样式文件(必须) -->
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <!-- 引入Bootstrap默认主题样式(可选) -->
  <link rel="stylesheet" href="css/bootstrap.theme.min.css">
  <!-- 你自己的样式或其他文件 -->
  <link rel="stylesheet" href="example.css">
</head>
<body>
  <!-- 你的HTML结构...... -->
  <!-- 以下代码,如果不使用JS插件则不需要 -->
  <!-- 由于Bootstrap的JS插件依赖jQuery,so 引入jQuery -->
  <script src="js/jquery.min.js"></script>
  <!-- 引入所有的Bootstrap的JS插件 -->
  <script src="bootstrap.min.js"></script>
  <!-- 你自己的脚本文件 -->
  <script src="example.js"></script>
</body>
</html>

Bootstrap文档

基础的Bootstrap模板

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap 101 Template</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

基础的Bootstrap模板,自己加了点注释,方便自己

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- viewport视口 shortcut: meta:vp -->
    <!-- 视口的作用:在移动浏览器中,当页面宽度超出设备,浏览器内部虚拟的一个页面容器,将页面容器缩放到设备这么大,然后展示 -->
    <!-- 此属性为移动端页面视口设置,当前值表示在移动段页面的宽度为设备的宽度,并且不缩放(缩放级别为1.0) -->
        <!-- with:视口的宽度  device-width表示设备的宽度 -->
        <!-- initial-scale:初始化缩放 -->
        <!-- user-scalable:是否允许用户自行缩放,取值为:yes/no 或者 0/1 -->
        <!-- minimum-scale:最小缩放,一般设置了用户不允许缩放,就没有必要设置最小和最大缩放了 -->
        <!-- maximum-scale:最大缩放 -->
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <!-- shortcut: meta:compat -->
    <!-- compatible此属性为文档兼容模式声明,content="IE=edge"表示如果在IE浏览器下则使用最新的标准渲染当前文本 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Title</title>
    <!-- bootstrap样式表 -->
    <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="css/mian.css">
    <!-- html5shiv作用:让低版本的浏览器可以识别HTML5中的新标签,如header,footer,section等 -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!-- respond作用: 让低版本浏览器可以支持css媒体查询功能 -->
    <!--[if lt IE 9]>
    <script src="./lib/html5shiv/html5shiv.min.js"></script>
    <script src="./lib/respond/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<!--由于bootstrap的js插件依赖jQuery,所以导入jQuery-->
<script src="./lib/jquery/jquery.js"></script>
<!--导入bootstrap的所有js插件-->
<script src="./lib/bootstrap/js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>

Compatible

<meta http-equiv="X-UA-Compatible" content="IE=edge">
  • 此属性为文档兼容模式声明,表示如果在IE浏览器下则使用最新的标准渲染当前文档

视口

<meta name="viewport" content="width=device-width, initial-scale=1">
  • 视口的作用:在移动浏览器中,当页面宽度超出设备,浏览器内部虚拟的一个页面容器,将页面容器缩放到设备这么大,然后展示
  • 目前大多数手机浏览器的视口(承载页面的容器)宽度都是980;
  • 视口的宽度可以通过meta标签设置
  • 此属性为移动端页面视口设置,当前值表示在移动端页面的宽度为设备的宽度,并且不缩放(缩放级别为1)
    • 视口的宽度
    • initial-scale:初始化缩放
    • user-scalable:是否允许用户自行缩放(值:yes/no; 1/0)
    • minimum-scale:最小缩放,一般设置了用户不允许缩放,就没必要设置最小和最大缩放
    • maximum-scale:最大缩放

条件注释

  • 条件注释的作用就是当判断条件满足时,就会执行注释中的HTML代码,不满足时会当做注释忽略掉

第三方依赖

  • jQuery

    Bootstrap框架中的所有JS组件都依赖于jQuery实现

  • html5shiv

    让低版本浏览器可以识别HTML5的新标签,如header、footer、section等

  • respond

    让低版本浏览器可以支持CSS媒体查询功能

建议以后在HTML中将脚步的引入放到页面最底下

mediaquery

@media (判断条件(针对于当前窗口的判断)){
    /*这里的代码只有当判断条件满足时才会执行*/
}

@media (min- 768px) and (max- 992px) {
  /*这里的代码只有当(min- 1280px)满足时才会执行*/
  .container {
     750px;
  }
}
  • 当使用min-width作为判断条件一定要从小到大,其原因是CSS从上往下执行
原文地址:https://www.cnblogs.com/gchlcc/p/6909222.html