美文网首页
html5源码笔记(四)【爱创课堂专业前端培训】

html5源码笔记(四)【爱创课堂专业前端培训】

作者: 爱创课堂 | 来源:发表于2019-08-22 18:29 被阅读0次

    一、响应式的实现-媒介查询

    @media

    实现方式一:把media限定到link中

    <div class="box1"></div>

    <div class="box2"></div>

    <!--响应式页面兼容移动端代码-->

    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

    <link rel="stylesheet" type="text/css" href="css/media1.css" media="screen and (max-width:1000px)"/>

    <link rel="stylesheet" type="text/css" href="css/media2.css" media="screen and (min-width:1000px) and (max-width:1500px)"/>

    <link rel="stylesheet" type="text/css" href="css/media3.css" media="screen and (min-width:1500px)"/>

    实现方式二:把media写到css代码中

    留活口,ie兼容

    @charset "utf-8";

    *{

    margin: 0;

    padding: 0;

    }

    aside{

    height: 200px;

    width: 20%;

    float: left;

    background: orange;

    }

    div{

    height: 200px;

    width: 40%;

    float: left;

    }

    div.box1{

    background: blue;

    }

    div.box2{

    background: pink;

    }

    @media only screen and (min-width: 1000px) and (max-width: 1500px) {

    aside{

    display: none;

    }

    div.box1{

    width: 50%;

    background: red;

    }

    div.box2{

    width: 50%;

    background: purple;

    }

    }

    @media only screen and (max-width: 1000px) {

    aside{

    display: none;

    }

    div.box1{

    width: 100%;

    background: yellow;

    }

    div.box2{

    width: 100%;

    background: greenyellow;

    }

    1 }

    二、bootstrap介绍

    2.1 bootstrap概述

    bootstrap 是世界上最受欢迎的前端框架,用于构建响应式、移动设备优先的网站。

    bootstrap分为“全局css样式”、“组件”、“javascript插件”这么几个主要的部分。

    设置全局 css 样式

    基本的 html 元素均可以通过 class 设置样式并得到增强效果;还有先进的栅格系统。

    组件

    无数可复用的组件,包括字体图标、下拉菜单、导航、警告框、弹出框等更多功能。

    javascript插件

    jquery 插件为 bootstrap 的组件赋予了“生命”。可以简单地一次性引入所有插件,或者逐个引入到你的页面中。

    2.2 bootstrap引入:

    npm 需要安装环境node.js

    cdn 在线方式,需要联网

    离线的方式 下载引入自己的网站中

    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-gn5384xqq1aowxa+058rxpxpg6fy4iwvtnh0e263xmfcjlsawiggfaw/dais6jxm" crossorigin="anonymous">

    1  <!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"--> 

    2.3 容器及标题标签

    类名.container根据不同视口给出不同的方案,但是都是页面居中的效果

    类名 .container-fluid 宽度百分百

    标题标签 单位rem 改变了w3c标准样式

    <div class="container border2">

      <!-- content here -->

      <h1>这是bootstrap</h1>

      <h2>这是bootstrap</h2>

      <h3>这是bootstrap</h3>

      <h4>这是bootstrap</h4>

      <h5>这是bootstrap</h5>

      <h6>这是bootstrap</h6>

    1  </div>

    2.4 媒体查询:

    // small devices (landscape phones, 576px and up)@media (min-width: 576px) { ... }

    // medium devices (tablets, 768px and up)@media (min-width: 768px) { ... }

    // large devices (desktops, 992px and up)@media (min-width: 992px) { ... }

    // extra large devices (large desktops, 1200px and up)@media (min-width: 1200px) { ... }

    或:

    // extra small devices (portrait phones, less than 576px)@media (max-width: 575.98px) { ... }

    // small devices (landscape phones, 576px and up)@media (min-width: 576px) and (max-width: 767.98px) { ... }

    // medium devices (tablets, 768px and up)@media (min-width: 768px) and (max-width: 991.98px) { ... }

    // large devices (desktops, 992px and up)@media (min-width: 992px) and (max-width: 1199.98px) { ... }

    // extra large devices (large desktops, 1200px and up)@media (min-width: 1200px) { ... }

    2.5 网格布局

    栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局,你的内容就可以放入这些创建好的布局中

    类名row 行必须包含在.container (固定宽度)或 .container-fluid (100% 宽度)中,以便为其赋予合适的排列(aligment)和内补(padding)。

    类名 col- 列、栏通过“行(row)”在水平方向创建一组“列(column)”,内容应当放置于“列(column)”内,并且,只有“列(column)”可以作为行(row)”的直接子元素

    一行一共有12栏,如果一行多余12栏,会自动换行

    响应式:

    .col-

    .col-sm-

    .col-md-

    .col-lg-

    .col-xl-

    偏移值:

    offset-  

    <div class="container">

      <div class="row">

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

      </div>

      <div class="row">

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

      </div>

      <div class="row">

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

      </div>

      <div class="row">

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

        <div class="col-sm">

          one of three columns

        </div>

      </div>

    </div>

    <div class="container-fluid">

       <div class="row">

       <div class="col-2">

       col-2

       </div>

       <div class="col-8">

       col-8

       </div>

       <div class="col-2">

       col-2

       </div>

      </div>

      <div class="row">

       <div class="col-3">

       col-3

       </div>

       <div class="col-6">

       col-6

       </div>

       <div class="col-3">

       col-3

       </div>

      </div>

    1  </div>

    2.6 文本与排版

    使用 Bootstrap 的排版特性,可以创建标题、段落、列表及其他内联元素,实际上它是把大部分在HTML的基本标签加了样式。

    <div class="container">

    <p class="text-left text-success bg-info">这是关于排版和文本效果的应用</p>

    <p class="text-center text-info bg-warning">这是关于排版和文本效果的应用</p>

    <p class="text-right text-warning bg-success">这是关于排版和文本效果的应用</p>

    <p class="text-hide"</p>

    <p class="text-danger bg-primary">这是关于排版和文本效果的应用</p>

    <p class="text-muted bg-danger">这是关于排版和文本效果的应用</p>

    1  </div>

    2.7 表格

    1 默认样式

    2 .table

    3 可选样式

    4 .table-striped为表格提供了斑马线的样式

    5 .table-bordered为表格增加边框(border)

    6 .table-hover 为表格中的每一行赋予鼠标悬停样式。鼠标划过后会添加一个背景色。

    7 .table-condensed 每个单元格的内补(padding)减半,可使表格更紧凑。

    <div class="container">

    <table class="table table-striped table-bordered table-hover table-warning table-sm">

      <thead>

        <tr class="bg-danger">

          <th scope="col">#</th>

          <th scope="col">First</th>

          <th scope="col">Last</th>

          <th scope="col">Handle</th>

        </tr>

      </thead>

      <tbody>

        <tr>

          <th scope="row">1</th>

          <td>Mark</td>

          <td>Otto</td>

          <td>@mdo</td>

        </tr>

        <tr>

          <th scope="row">2</th>

          <td>Jacob</td>

          <td>Thornton</td>

          <td>@fat</td>

        </tr>

        <tr>

          <th scope="row">3</th>

          <td>Larry</td>

          <td>the Bird</td>

          <td>@twitter</td>

        </tr>

      </tbody>

    </table>

    1  </div>

    2.7 表单

    2.8 按钮

    <div class="container-fluid">

    <button type="button" class="btn btn-primary">Primary</button>

    <button type="button" class="btn btn-secondary">Secondary</button>

    <button type="button" class="btn btn-success">Success</button>

    <button type="button" class="btn btn-danger">Danger</button>

    <button type="button" class="btn btn-warning">Warning</button>

    <button type="button" class="btn btn-info">Info</button>

    <button type="button" class="btn btn-light">Light</button>

    <button type="button" class="btn btn-dark">Dark</button>

    <button type="button" class="btn btn-link">Link</button>

    </div>

    <div class="container">

    <button type="button" class="btn btn-primary">按钮</button>

    <button type="button" class="btn btn-primary">按钮</button>

    <button type="button" class="btn btn-primary">按钮</button>

    <button type="button" class="btn btn-primary">按钮</button>

    </div>

    <div class="container">

    <button type="button" class="btn btn-light">按钮</button>

    <button type="button" class="btn btn-light">按钮</button>

    <button type="button" class="btn btn-light">按钮</button>

    <button type="button" class="btn btn-light">按钮</button>

    1  </div>

    2.9 卡片 面包屑

    <div class="container">

    <div class="row">

    <div class="col-4">

    <div class="card" style="width: 18rem;">

      <img class="card-img-top" src="images/1.jpg" alt="Card image cap">

      <div class="card-body">

        <h5 class="card-title">Card title</h5>

        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>

        <a href="#" class="btn btn-primary">Go somewhere</a>

      </div>

    </div>

    </div>

    <div class="col-4">

    <div class="card" style="width: 18rem;">

      <img class="card-img-top" src="images/1.jpg" alt="Card image cap">

      <div class="card-body">

        <h5 class="card-title">Card title</h5>

        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>

        <a href="#" class="btn btn-primary">Go somewhere</a>

      </div>

    </div>

    </div>

    <div class="col-4">

    <div class="card" style="width: 18rem;">

      <img class="card-img-top" src="images/1.jpg" alt="Card image cap">

      <div class="card-body">

        <h5 class="card-title">Card title</h5>

        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>

        <a href="#" class="btn btn-primary">Go somewhere</a>

      </div>

    </div>

    </div>

    </div>

    1  </div>

    2.9 轮播图

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <link rel="stylesheet" type="text/css" href="bootstrap-4.0.0-dist/css/bootstrap.css"/>

    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

    <script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>

    <script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    </head>

    <body>

    <div class="container">

    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">

      <ol class="carousel-indicators">

        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>

        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>

        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>

      </ol>

      <div class="carousel-inner">

        <div class="carousel-item active">

          <img class="d-block w-100" src="images/1.jpg" alt="First slide">

        </div>

        <div class="carousel-item">

          <img class="d-block w-100" src="images/2.jpg" alt="Second slide">

        </div>

        <div class="carousel-item">

          <img class="d-block w-100" src="images/3.jpg" alt="Third slide">

        </div>

      </div>

      <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">

        <span class="carousel-control-prev-icon" aria-hidden="true"></span>

        <span class="sr-only">Previous</span>

      </a>

      <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">

        <span class="carousel-control-next-icon" aria-hidden="true"></span>

        <span class="sr-only">Next</span>

      </a>

    </div>

    </div>

    </body>

    </html>

    关注VX公众号“icketang” 免费领取华为荣耀商城项目实战视频教程

    相关文章

      网友评论

          本文标题:html5源码笔记(四)【爱创课堂专业前端培训】

          本文链接:https://www.haomeiwen.com/subject/oweosctx.html