bootstrap使用案例

bootstrap布局

css
.col-xs-2{
    width: 20%;
    text-align: center;
    padding: 10px 0px;
}

<div class="container-fiuid">
    
    <div class="row">
        
        <div class="col-xs-2">
            <img src="./img/pic11.png" alt="">
            <p>美食p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic12.png" alt="">
            <p>猫眼电影p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic13.png" alt="">
            <p>酒店p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic14.png" alt="">
            <p>休闲娱乐p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic15.png" alt="">
            <p>外卖p>
        div>
    div>
    <div class="row">
        <div class="col-xs-2">
            <img src="./img/pic16.png" alt="">
            <p>KTVp>
        div>
        <div class="col-xs-2">
            <img src="./img/pic17.png" alt="">
            <p>周边游p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic18.png" alt="">
            <p>丽人p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic19.png" alt="">
            <p>小吃快餐p>
        div>
        <div class="col-xs-2">
            <img src="./img/pic20.png" alt="">
            <p>机票/火车票p>
        div>
    div>
div>

列表


    "list-unstyled list-inline" >
  • 1
  • 2
  • 3
  • 4
  • 5

表格


"table table-bordered text-center">
    
1 2 3
1 2 3
1 2 3




"table table-striped table-hover text-center table-condensed">
    "success">
        "info">
        "danger">
        
1 2 3
1 2 3
1 2 3

表单

bootstrap登入验证

css

<div class="col-xs-4 col-xs-offset-4">
    <form class="form-horizontal">
        <div class="form-group has-feedback">
            <label for="user" class="control-label col-xs-3">user:label>
            <div class="col-xs-9"><input type="text" id="user" class="form-control"><span class="glyphicon form-control-feedback">span>div>
        div>
        <div class="form-group has-feedback">
            <label for="password" class="control-label col-xs-3">password:label>
            <div class="col-xs-9"><input type="password" id="password" class="form-control"><span class="glyphicon form-control-feedback">span>div>
        div>
        <div class="form-group has-feedback">
            <label for="password" class="control-label col-xs-3">tel:label>
            <div class="col-xs-9"><input type="text" id="tel" class="form-control"><span class="glyphicon form-control-feedback">span>div>
        div>
        <div class="form-group">
            <label for="search" class="control-label col-xs-3">search:label>
            <div class="col-xs-9"><input type="text" id="search" class="form-control"><span class="form-control-feedback glyphicon glyphicon-search">span>div>
        div>
        <div class="row">
            <div class="col-xs-2 col-xs-offset-4"><button type="submit" class="btn btn-primary">提交button>div>
            <div class="col-xs-2 col-xs-offset-3"><button type="button" class="btn btn-default">注册button>div>
        div>
    form>
div>
(function($){
    $.fn.verify=function(){
        var arr=["user","password","tel"];
        // 判断数组里面是否包含id,return出去
        // if(!(["user","password"].includes(this.prop("id")))) return
        if(arr.indexOf(this.prop("id"))<0) return;
        // input事件
        this.on("input",e=>{
            if(this.data("ids"))return;
            var ids=setTimeout(()=>{
                clearTimeout(this.data("ids"));
                this.data("ids",false);
                if(verifyReg(this.prop("id"),this.val())){
                    this.next("span").removeClass("glyphicon-remove")
                    .addClass("glyphicon-ok")
                    .parents(".has-feedback")
                    .removeClass("has-error")
                    .addClass("has-success");
                }else{
                    this.next("span")
                    .removeClass("glyphicon-ok")
                    .addClass("glyphicon-remove")
                    .parents(".has-feedback")
                    .removeClass("has-success")
                    .addClass("has-error");;
                }
            },500)
            this.data("ids",ids)
        })
    };
    // 判断内容是否正确
    function verifyReg(id,text){
        switch (id){
            case "user":
                return /^\w{8,16}$/.test(text);
            case "password":
                return /^(?=\D+\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,16}$/.test(text);
            case "tel":
                return /^1\d{10}$/.test(text);    
        }
    }
})($);

$("#user").verify();
$("#password").verify();
$("#tel").verify();

按钮




<button class="btn btn-default btn-lg active">按钮button>
<button class="btn btn-primary " disabled="disabled">按钮button>
<div  class="btn btn-danger">按钮div>
<a href="#"  class="btn btn-success">按钮a>
<span  class="btn btn-danger">按钮span>
<button class="btn btn-link">超链接button>

图片


<img src="./img/pic11.png" class="img-rounded">
<img src="./img/pic12.png" class="img-circle">
<img src="./img/pic13.png" class="img-thumbnail">

文本


<div class="text-danger bg-primary">文本div>

<span class="close">×span>

<span class="caret">span>

快速浮动

<div class="clearfix">
    <div class="pull-left">1div>
    <div class="pull-left">1div>
    <div class="pull-left">1div>
    <div class="pull-left">1div>
div>

显示或隐藏内容

<div class="show">显示div>
<div class="hidden">隐藏div>


$("div").hover(function(){
    $(this).toggleClass("hidden");
})

组合按钮


<button class="btn btn-danger"><span class="glyphicon glyphicon-search">span>搜索button>







<div class="btn-toolbar">
    <div class="btn-group">
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-left">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-center">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-right">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-justify">span>button>
    div>
    <div class="btn-group">
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-left">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-center">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-right">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-justify">span>button>
    div>
    <div class="btn-group">
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-left">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-center">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-right">span>button>
        <button class="btn btn-default"><span class="glyphicon glyphicon-align-justify">span>button>
    div>
div>

下拉菜单

将下拉菜单触发器和下拉菜单都包裹在 .dropdown 里加入组成菜单的 HTML 代码
dropdown-toggle 下拉菜单切换
dropdown-menu 下拉菜单
divider 分割线
把任意一个按钮放入 .btn-group 中,然后加入适当的菜单标签,就可以让按钮作为菜单的触发器
<div class="dropdown">
    <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        <span>北京span><span class="caret">span>
    button>
    <ul class="dropdown-menu">
        <li class="dropdown-header">首都li>
        <li><a href="#">北京a>li>
        <li class="divider">li>
        <li class="dropdown-header">直辖市li>
        <li><a href="#">上海a>li>
        <li><a href="#">深圳a>li>
        <li><a href="#">武汉a>li>
        <li class="disabled"><a href="#">广州a>li>
        <li><a href="#">杭州a>li>
    ul>
div>

按钮式下拉菜单


<div class="dropdown btn-group">
    <button class="btn btn-default dropdown-toggle">
        <span>北京span>button>
    <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        <span class="caret">span>
    button>
    <ul class="dropdown-menu">
        <li class="dropdown-header">首都li>
        <li><a href="#">北京a>li>
        <li class="divider">li>
        <li class="dropdown-header">直辖市li>
        <li><a href="#">上海a>li>
        <li><a href="#">深圳a>li>
        <li><a href="#">武汉a>li>
        <li class="disabled"><a href="#">广州a>li>
        <li><a href="#">杭州a>li>
    ul>
div>
<script>
    // 点击菜单或者超链接显示点击的文本内容
    $(".dropdown-menu a").click(function(){
        $(".dropdown span:first").text(this.textContent);
    })
script>

组件

输入框组


导航

标签页

<ul class="nav nav-tabs">
    <li class="active"><a href="#">首页</a></li>
    <li><a href="#">新手问答</a></li>
    <li><a href="#">游戏简介</a></li>
    <li><a href="#">英雄攻略</a></li>
    <li><a href="#">游戏下载</a></li>
</ul>
<script>
    $("li").click(function(){
        // 当前元素添加active样式,其它兄弟元素中是active的删除
        $(this).addClass("active").siblings(".active").removeClass("active");
    })
</script>

胶囊式标签页

<ul class="nav nav-pills">
    <li class="active"><a href="#">首页</a></li>
    <li><a href="#">新手问答</a></li>
    <li><a href="#">游戏简介</a></li>
    <li><a href="#">英雄攻略</a></li>
    <li><a href="#">游戏下载</a></li>
</ul>
<script>
    $("li").click(function(){
        // 当前元素添加active样式,其它兄弟元素中是active的删除
        $(this).addClass("active").siblings(".active").removeClass("active");
    })
</script>

导航添加下拉菜单

<!-- nav-justified 两端对齐 -->
<ul class="nav nav-tabs nav-justified">
    <li class="active"><a href="#">首页</a></li>
    <li><a href="#">新手问答</a></li>
    <li><a href="#">游戏简介</a></li>
    <li><a href="#">英雄攻略</a></li>
    <li><a href="#">游戏下载</a></li>
    <li class="dropdown btn-group">
        <a class="btn btn-default dropdown-toggle">
            <span>北京</span></a>
        <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
            <li class="dropdown-header">首都</li>
            <li><a href="#">北京</a></li>
            <li class="divider"></li>
            <li class="dropdown-header">直辖市</li>
            <li><a href="#">上海</a></li>
            <li><a href="#">深圳</a></li>
            <li><a href="#">武汉</a></li>
            <li class="disabled"><a href="#">广州</a></li>
            <li><a href="#">杭州</a></li>
        </ul>
    </li>
</ul>
   
<script>
    $("li").click(function(){
        // 当前元素添加active样式,其它兄弟元素中是active的删除
        $(this).addClass("active").siblings(".active").removeClass("active");
    })
</script>

分页



<ul class="pagination" id="page1" data-active="2">
    <li data-toggle="prev"><a href="#">«a>li>
    <li><a href="#">1a>li>
    <li class="active"><a href="#">2a>li>
    <li><a href="#">3a>li>
    <li><a href="#">4a>li>
    <li><a href="#">5a>li>
    <li><a href="#">6a>li>
    <li><a href="#">7a>li>
    <li><a href="#">8a>li>
    <li><a href="#">9a>li>
    <li data-toggle="next"><a href="#">»a>li>
ul>

$("li").click(function (e) {
    var ul=$(".pagination");
    var li;
    if($(this).attr("data-toggle")==="prev"){
         if(ul.attr("data-active")==="1")return;
        li=$(".pagination>.active").removeClass("active").prev().addClass("active");
        ul.attr("data-active",li.text());
    }else if($(this).attr("data-toggle")==="next"){
        if(ul.attr("data-active")==ul.children().length-2)return;
        li=$(".pagination>.active").removeClass("active").next().addClass("active");
        ul.attr("data-active",li.text());
    }else {
        $(this)
            .addClass("active")
            .siblings(".active")
            .removeClass("active")
            .parent().attr("data-active",$(this).text());
    }
})

// 封装
(function(){
    $.fn.pageInit=function(){
        var li;
        this.children().click(e=>{
            if($(e.currentTarget).attr("data-toggle")=="prev"){
                if(this.attr("data-active")==="1") return;
                li=this.children(".active")
                	.removeClass("active")
                	.prev().addClass("active");
                this.attr("data-active",li.text());
            }else if($(e.currentTarget).attr("data-toggle")=="next"){
                if(this.attr("data-active")==this.children().length-2) return;
                li=this.children(".active")
                    .removeClass("active")
                    .next().addClass("active");
                this.attr("data-active",li.text());
            }else{
                $(e.currentTarget)
                .addClass("active")
                .siblings(".active")
                .removeClass("active")
                .parent().attr("data-active",e.currentTarget.text());
            }
        })
    }
})();

$("#page1").pageInit()

<span class="label label-danger">Dangerspan>

<button class="btn btn-primary" type="button">
    Messages <span class="badge">4span>
button>

模态框


<button class="btn btn-default"  data-target="#myModal" data-toggle="modal">打开button>

<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">×button>
                <h4 class="modal-title text-centent">弹出窗标题h4>
            div>
            <div class="modal-body">
                <input type="text" id="msg">
                <pre>
Overflowing text to show scroll behavior
Cras mattis consectetur purus sit amet fermentum. 
Cras justo odio, dapibus ac facilisis in, egestas eget quam.
                pre>
            div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭button>
                <button class="btn btn-primary">保存button>
            div>
        div>
    div>
div>
<div id="msgs">div>
// 模态框初始化之后就立即显示出来
$('#myModal').modal({
    show: true
})

// 监听并执行自己的代码
$("#myModal").on("hide.bs.modal",function(e){
    $("#msgs").text($("#msg").val())
})

提示信息

<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>

<script>
    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    })
</script>

手风琴效果

<div class="panel-group col-xs-6" id="accordion" >
    <div class="panel panel-default">
        <div class="panel-heading"  id="headingOne">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" >
                    Collapsible Group Item #1
                a>
            h4>
        div>
        <div id="collapseOne" class="panel-collapse collapse in">
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            div>
        div>
    div>
    <div class="panel panel-default">
        <div class="panel-heading"  id="headingTwo">
            <h4 class="panel-title">
                <a class="collapsed"  data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" >
                    Collapsible Group Item #2
                a>
            h4>
        div>
        <div id="collapseTwo" class="panel-collapse collapse"  >
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            div>
        div>
    div>
    <div class="panel panel-default">
        <div class="panel-heading"  id="headingThree">
            <h4 class="panel-title">
                <a class="collapsed"  data-toggle="collapse" data-parent="#accordion" href="#collapseThree" >
                    Collapsible Group Item #3
                a>
            h4>
        div>
        <div id="collapseThree" class="panel-collapse collapse" >
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            div>
        div>
    div>
div>

轮播图效果


.carousel-indicators li{
    width: 20px;
    height: 20px;
}
.carousel-indicators .active
{
    width: 22px;
    height: 22px;
}
.carousel-control.left {
    background-image:none;
    filter:none;
}
.carousel-control.right {
    background-image:none;
    filter:none;
}
<div class="col-xs-12">
    <div class="carousel slide" id="myCarousel">
        <ul class="carousel-indicators">
            <li class="active" data-target="#myCarousel" data-slide-to="0"><a href="#">a>li>
            <li data-target="#myCarousel" data-slide-to="1"><a href="#">a>li>
            <li data-target="#myCarousel" data-slide-to="2"><a href="#">a>li>
            <li data-target="#myCarousel" data-slide-to="3"><a href="#">a>li>
            <li data-target="#myCarousel" data-slide-to="4"><a href="#">a>li>
        ul>
        <div class="carousel-inner">
            <div class="item active">
                <img src="img/a.png">
                <h3 class="carousel-caption">图片1h3>
            div>
            <div class="item">
                <img src="img/b.png">
                <h3 class="carousel-caption">图片2h3>
            div>
            <div class="item">
                <img src="img/c.png">
                <h3 class="carousel-caption">图片3h3>
            div>
            <div class="item">
                <img src="img/d.png">
                <h3 class="carousel-caption">图片4h3>
            div>
            <div class="item">
                <img src="img/e.png">
                <div class="carousel-caption">图片5div>
            div>
        div>
        <a class="carousel-control left" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-chevron-left">span>a>
        <a class="carousel-control right" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-chevron-right">span>a>
    div>
div>

你可能感兴趣的:(bootstrap,html5,前端)