bootstrap5.x 基础二(组件)

这里所使用的版本为5.x

本文主要整理两大块:

  1. bootstrap组件

  2. bootstrap通用类

前言:

开始前先了解一个缩写词(aria)
Accessible Rich Internet Application
可取得的丰富的互联网应用.

html5针对html tag增加的属性:role 和 aria-*。
role的作用是描述一个非标准的tag的实际作用。比如用div做button,那么设置div 的 role=“button”,辅助工具就可以认出这实际上是个button。
而aria-*的作用就是描述这个tag在可视化的情境中的具体信息。比如,
辅助工具就会知道,这个div实际上是个checkbox的角色,为选中状态。 当然,这些在页面都没有实际作用。

文中用说明部分的bs指代bootstrap,代码部分bs就是bs

前置准备:到官网或者中文网下载好bootstrap5.x的包。其次是页面的基本文件引入,css文件在头部引入,js文件在底部引入确保能读取到节点。如下:

doctype html>
<html lang="en">
  <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">

    <title>Hello, world!title>
  head>
  <body>
    <h1>Hello, world!h1>
    
    <script src="dist/js/bootstrap.bundle.min.js" >script>

    
    
  body>
html>

组件

手风琴

这里需要说明的可能就是,几个属性。

  1. accordion-header 里面的按钮,点击的时候需要展开关联的内容,这里是把关联属性的id记录在按钮的data-bs-target属性中,来确定点击的时候要展开那个内容

  2. 在accordion-collapse 中,需要添加两个属性,一个是关联的header的id,保存在aria-labelledby属性中,还有一个是保存整个accordion的id的属性data-bs-parent

  3. 内容上加了属性后默认是隐藏的,添加show类名的时候展示,而列表项则用是否有collapsed类来判断是否为展开,有标示展开状态,去掉标示关闭状态

    组件这块每个结构都需要记住,没多需要讲的,一般就直接复制主体,修改内容

    例子:

    <div class="accordion" id="accordionExample">
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingOne">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
            Accordion Item #1
          button>
        h2>
        <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
          <div class="accordion-body">
            <strong>This is the first item's accordion body.strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-bodycode>, though the transition does limit overflow.
          div>
        div>
      div>
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingTwo">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
            Accordion Item #2
          button>
        h2>
        <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
          <div class="accordion-body">
            <strong>This is the second item's accordion body.strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-bodycode>, though the transition does limit overflow.
          div>
        div>
      div>
    div>
    

    警告框(alerts)

​ 语法: 基础类:alert

​ 警告框类型: alert-{type}

​ type的可用值:primarysecondarysuccessdangerwarninginfolightdark

​ 例子:

<div class="alert alert-danger">
  有一个错误需要处理一下
div>

​ 提示框的显示和隐藏:默认是显示出来,可添加fade类名使其淡出

例如:

<div class="alert alert-danger fade">  有一个错误需要处理一下div>

徽章

基础类 : badge

样式类: bg-{type}

type的可用值: primarysecondarysuccessdangerwarninginfolightdark

例子 :

<span class="badge bg-primary">Primaryspan>
<span class="badge bg-secondary">Secondaryspan>

面包屑导航

面包屑导航最外层是由

你可能感兴趣的:(蓝桥web,bootstrap,前端,javascript)