学会Web UI框架--Bootstrap,快速搭建出漂亮的前端界面

简介: 学会Web UI框架--Bootstrap,快速搭建出漂亮的前端界面

✨✨ 欢迎大家来到景天科技苑✨✨

🎈🎈 养成好习惯,先赞后看哦~🎈🎈

Bootstrap

Bootstrap官网

1.Bootstrap介绍

一、什么是Bootstrap?

bootstrap是一个基于HTML、CSS和Javascript语言编写的框架,具有简单、灵活的特性,拥有样式库、组件和插件,bootstrap常用来开发响应式布局和移动设备优先的Web项目,能够帮助开发者快速搭建前端页面。

Bootstrap诞生于2011年,来自Twitter公司,是目前最受欢迎的前端框架

是一个用于快速开发Web应用程序和网站的前端框架

Bootstrap是基于HTML、CSS、JS的,简洁灵活,使得Web开发更加快捷

概述:Bootstrap是一个建立一个页面,就可以在三个终端(PC端、平板、手机)上完美展示的响应式前端框架

二、为什么要用Bootstrap

因为Bootstrap是一个简洁、直观、强悍的前端开发框架,让web开发更迅速、更容易上手。

封装了常用的css样式,js动态效果。直接调用

使用bootstrap的宗旨就是 ctrl c / ctrl v

三、如何使用Bootstrap

1.下载Bootstrap库 https://v4.bootcss.com/(Bootstrap管网)

2.页面中引入库

jquery-3.3.1.js:jQuery库【注意:必须在Bootstrap核心库引入之前引入jQuery库】

bootstrap.css:Bootstrap核心样式【添加到head标签中】

使用最新版

下载

并且提供CDN加速在线引入

解压后包含两个文件夹

不管是css,还是js,带min的都是压缩过的。生产中使用压缩过的


解压后,在项目中引入

2.简单使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    适配IE浏览器的edge浏览器
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   适配手机端,自适应手机屏幕大小,调整分辨率,方便手机观看 
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bootstrap简单使用</title>
    <script src="jquery.js"></script>
    <!--    引入外部bootstrap样式-->
    <link rel="stylesheet" href="bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css" />
</head>

没做手机屏幕适配之前,很小看不清

做了手机屏幕适配后,等比例缩放,但是这样缩放可能会导致页面显示不完内容。因此这就需要做响应式

我们不用设置任何样式,只需引入bootstrap自带的css样式即可

<body>
   <table class="table table-hover table-striped">
        <thead>
            <tr>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>孙坚</td>
                <td>男</td>
                <td>18</td>
            </tr>
            <tr>
                <td>王涛</td>
                <td>男</td>
                <td>20</td>
            </tr>

            <tr>
                <td>王舒展</td>
                <td>女</td>
                <td>20</td>
            </tr>
            <tr>
                <td>刘亦菲</td>
                <td>女</td>
                <td>24</td>
            </tr>
        </tbody>
    </table>
</body>

浏览器显示效果

</html>
 

3.布局容器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>

        .c1{
            background-color:tan;
            height:100px;
        }
        .c2{
            background-color:pink;
            height:100px;
        }
        .c3{
            background-color:green;
            height:100px;
        }

    </style>
</head>
<body>
<!-- container-fluid占满整个屏幕 -->

<!-- container 左右两边有留白 -->

<div class="container-fluid">

    <div class="row">
<!--        //  col-md-offset-3  栅格偏移,向右偏移3个栅格的意思-->
<!--        //  col-md-6 占6个栅格,默认从左边开始-->
        <div class="col-md-6 c1 col-md-offset-3">
            <div class="row">
                <div class="col-md-6 c3"></div>
            </div>

        </div>
<!--        <div class="col-md-8 c2"></div>-->

    </div>


</div>
<!--<div class="container c1"></div>-->

栅格单位,铺满是12个栅格,各占6个

如果是占不满,留空白

如果两个加起来超过12个,则第二个换行

新版的栅格偏移,默认从左边开始,设置了栅格偏移可以从指定栅格开始

具体使用方法,可以参照官网使用说明,很详细

缩小屏幕等分,不会换行

</body>
<script src="jquery.js"></script>
</html>

4.Bootstrap实现轮播图

轮播图必须引入在bootstrap.js之前引入jQuery.js

设置轮播图轮换图片间隔时间,默认是5秒

还可以通过js方法控制轮播时间

轮播图完整代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>轮播图</title>
    <script src="jquery.js"></script>
    <link rel="stylesheet" href="bootstrap-4.6.2-dist/css/bootstrap.min.css" />
    <script src="bootstrap-4.6.2-dist/js/bootstrap.min.js"></script>
  </head>
  <body>
    <div
      id="carouselExampleCaptions"
      class="carousel slide"
      data-ride="carousel"
    >
      <ol class="carousel-indicators">
        <li
          data-target="#carouselExampleCaptions"
          data-slide-to="0"
          class="active"
        ></li>
        <li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
        <li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img src="1.jpg" class="d-block w-100" alt="..." />
          <div class="carousel-caption d-none d-md-block">
            <h5>First slide label</h5>
            <p>Some representative placeholder content for the first slide.</p>
          </div>
        </div>
        <div class="carousel-item">
          <img src="2.jpg" class="d-block w-100" alt="..." />
          <div class="carousel-caption d-none d-md-block">
            <h5>Second slide label</h5>
            <p>Some representative placeholder content for the second slide.</p>
          </div>
        </div>
        <div class="carousel-item">
          <img src="3.jpg" class="d-block w-100" alt="..." />
          <div class="carousel-caption d-none d-md-block">
            <h5>Third slide label</h5>
            <p>Some representative placeholder content for the third slide.</p>
          </div>
        </div>
      </div>
      <button
        class="carousel-control-prev"
        type="button"
        data-target="#carouselExampleCaptions"
        data-slide="prev"
      >
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </button>
      <button
        class="carousel-control-next"
        type="button"
        data-target="#carouselExampleCaptions"
        data-slide="next"
      >
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </button>
    </div>
  </body>

  <script>
    $(".carousel").carousel({
      interval: 2000,
    });
  </script>
</html>

效果,图片轮换播放:


相关文章
|
12月前
|
机器学习/深度学习 算法 定位技术
Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现裂缝的检测识别(C#代码UI界面版)
本项目基于YOLOv8模型与C#界面,结合Baumer工业相机,实现裂缝的高效检测识别。支持图像、视频及摄像头输入,具备高精度与实时性,适用于桥梁、路面、隧道等多种工业场景。
1315 27
|
9月前
|
开发框架 前端开发 Go
【GoGin】(0)基于Go的WEB开发框架,GO Gin是什么?怎么启动?本文给你答案
Gin:Go语言编写的Web框架,以更好的性能实现类似Martini框架的APInet/http、Beego:开源的高性能Go语言Web框架、Iris:最快的Go语言Web框架,完备的MVC支持。
679 1
|
开发框架 JSON 中间件
Go语言Web开发框架实践:路由、中间件、参数校验
Gin框架以其极简风格、强大路由管理、灵活中间件机制及参数绑定校验系统著称。本文详解其核心功能:1) 路由管理,支持分组与路径参数;2) 中间件机制,实现全局与局部控制;3) 参数绑定,涵盖多种来源;4) 结构体绑定与字段校验,确保数据合法性;5) 自定义校验器扩展功能;6) 统一错误处理提升用户体验。Gin以清晰模块化、流程可控及自动化校验等优势,成为开发者的优选工具。
|
开发框架 安全 前端开发
Go Web开发框架实践:模板渲染与静态资源服务
Gin 是一个功能强大的 Go Web 框架,不仅适用于构建 API 服务,还支持 HTML 模板渲染和静态资源托管。它可以帮助开发者快速搭建中小型网站,并提供灵活的模板语法、自定义函数、静态文件映射等功能,同时兼容 Go 的 html/template 引擎,具备高效且安全的页面渲染能力。
|
开发框架 JSON 中间件
Go语言Web开发框架实践:使用 Gin 快速构建 Web 服务
Gin 是一个高效、轻量级的 Go 语言 Web 框架,支持中间件机制,非常适合开发 RESTful API。本文从安装到进阶技巧全面解析 Gin 的使用:快速入门示例(Hello Gin)、定义 RESTful 用户服务(增删改查接口实现),以及推荐实践如参数校验、中间件和路由分组等。通过对比标准库 `net/http`,Gin 提供更简洁灵活的开发体验。此外,还推荐了 GORM、Viper、Zap 等配合使用的工具库,助力高效开发。
|
人工智能 安全 程序员
用 Colab 和 ngrok 免费部署你的 Web UI 项目,随时随地访问!
用 Colab 和 ngrok 免费部署你的 Web UI 项目,随时随地访问!
1599 12
N..
|
开发框架 前端开发 UED
Bootstrap的CSS组件
Bootstrap的CSS组件
N..
330 0
|
前端开发 容器
|
前端开发 容器
|
前端开发 开发者 容器

热门文章

最新文章