网址
bootstrap官网:https://getbootstrap.com
bootstrap4文档:https://getbootstrap.com/docs 高版本右上方可以切换到低版本。
bootstrap3文档:https://getbootstrap.com/docs/3.3/
bootstrap4 相对于bootstrap3的改变:https://getbootstrap.com/docs/4.2/migration/
bootstrap github:https://github.com/twbs/bootstrap
安装bootstrap css
使用bootstrap方式:
方式1:链接外部库
https://www.bootstrapcdn.com/legacy/bootstrap/
1 2 3 4 5 6 7 8 9 10 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > </head > <body > <button type ="button" class ="btn btn-primary" > Primary</button > </body > </html >
方式2:下载源文件,并link
1 <link rel="stylesheet" type="text/css" href="bootstrap.css">
实验
1、实验jumbotron
2、实验多行表单与form-inline一行表单
form-group添加一些属性
form-control让输入框扩展一行显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > <link rel ="stylesheet" type ="text/css" href ="bootstrap.css" > </head > <body > <div class = "container" > <button type ="button" class ="btn btn-primary" > Primary</button > <div class ="jumbotron" > <h1 > Hello, world!</h1 > <p > ...</p > <p > <a class ="btn btn-primary btn-lg" href ="#" role ="button" > Learn more</a > </p > </div > <form > <div class ="form-group" > <label for ="exampleInputEmail1" > Email address</label > <input type ="email" class ="form-control" id ="exampleInputEmail1" placeholder ="Email" > </div > <div class ="form-group" > <label for ="exampleInputPassword1" > Password</label > <input type ="password" class ="form-control" id ="exampleInputPassword1" placeholder ="Password" > </div > <div class ="form-group" > <label for ="exampleInputFile" > File input</label > <input type ="file" id ="exampleInputFile" > <p class ="help-block" > Example block-level help text here.</p > </div > <div class ="checkbox" > <label > <input type ="checkbox" > Check me out </label > </div > <button type ="submit" class ="btn btn-default" > Submit</button > </form > <form class ="form-inline" > <div class ="form-group" > <label for ="exampleInputName2" > Name</label > <input type ="text" class ="form-control" id ="exampleInputName2" placeholder ="Jane Doe" > </div > <div class ="form-group" > <label for ="exampleInputEmail2" > Email</label > <input type ="email" class ="form-control" id ="exampleInputEmail2" placeholder ="jane.doe@example.com" > </div > <button type ="submit" class ="btn btn-default" > Send invitation</button > </form > </div > </body > </html >
导航栏
第一步,添加前方navbar-header头部
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > <link rel ="stylesheet" type ="text/css" href ="bootstrap.css" > </head > <body > <nav class ="navbar navbar-default" > <div class ="container" > <div class ="navbar-header" > <a class ="navbar-brand" href ="#" > Brand</a > </div > </div > </body > </html >
第2步,添加导航栏菜单navbar-nav
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > </head > <body > <nav class ="navbar navbar-default" > <div class ="container" > <div class ="navbar-header" > <a class ="navbar-brand" href ="#" > Brand</a > </div > <ul class ="nav navbar-nav" > <li > <a href ="#" > About</a > </li > <li > <a href ="#" > Contact</a > </li > </ul > <ul class ="nav navbar-nav navbar-right" > <li > <a href ="#" > Sign Up</a > </li > <li > <a href ="#" > Login</a > </li > </ul > </div > </body > </html >
菜单栏的缩放
需要使用js,带入bootstrap js
1 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
bootstrap js需要jquery
1 2 3 4 <script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
header内添加 缩放button
属性 data-target="#bs-nav-demo" 意味着点击缩放按钮,显示id为bs-nav-demo的菜单内的内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > </head > <body > <nav class ="navbar navbar-default" > <div class ="container" > <div class ="navbar-header" > <button type ="button" class ="navbar-toggle collapsed" data-toggle ="collapse" data-target ="#bs-nav-demo" aria-expanded ="false" > <span class ="sr-only" > Toggle navigation</span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > </button > <a class ="navbar-brand" href ="#" > Brand</a > </div > <ul class ="nav navbar-nav" > <li > <a href ="#" > About</a > </li > <li > <a href ="#" > Contact</a > </li > </ul > <ul class ="nav navbar-nav navbar-right" > <li > <a href ="#" > Sign Up</a > </li > <li > <a href ="#" > Login</a > </li > </ul > </div > <script src ="https://code.jquery.com/jquery-2.2.4.js" integrity ="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin ="anonymous" > </script > <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity ="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin ="anonymous" > </script > </body > </html >
在nav-bar中添加id为bs-nav-demo的div。 意味着缩小屏幕会隐藏内部的内容。点击后会显示。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > </head > <body > <nav class ="navbar navbar-default" > <div class ="container" > <div class ="navbar-header" > <button type ="button" class ="navbar-toggle collapsed" data-toggle ="collapse" data-target ="#bs-nav-demo" aria-expanded ="false" > <span class ="sr-only" > Toggle navigation</span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > </button > <a class ="navbar-brand" href ="#" > Brand</a > </div > <div class ="collapse navbar-collapse" id ="bs-nav-demo" > <ul class ="nav navbar-nav" > <li > <a href ="#" > About</a > </li > <li > <a href ="#" > Contact</a > </li > </ul > <ul class ="nav navbar-nav navbar-right" > <li > <a href ="#" > Sign Up</a > </li > <li > <a href ="#" > Login</a > </li > </ul > </div > </div > <script src ="https://code.jquery.com/jquery-2.2.4.js" integrity ="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin ="anonymous" > </script > <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity ="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin ="anonymous" > </script > </body > </html >
gird系统
将一个区域分为了12个块。 break-point:
极小屏幕:.col-xs- 小屏幕:.col-sm- 中屏幕:.col-md- 大屏幕:.col-lg-
小屏幕不设置,默认是占满,大屏幕不设置默认和最近的小屏幕的规则相同。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > <style type ="text/css" > .pink { background: pink; border: 1px solid purple; } .orange { background: orange; border: 1px dashed red; height: 50px; } </style > </head > <body > <div class ="row" > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > <div class ="col-lg-1 col-md-2 col-sm-4 pink" > COL LG 1</div > </div > <script src ="https://code.jquery.com/jquery-2.2.4.js" integrity ="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin ="anonymous" > </script > <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity ="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin ="anonymous" > </script > </body > </html >
##grid嵌套
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 <!DOCTYPE html> <html > <head > <title > BootStrap</title > <link href ="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel ="stylesheet" integrity ="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin ="anonymous" > <style type ="text/css" > .pink { background: pink; border: 1px solid purple; } .orange { background: orange; border: 1px dashed red; height: 50px; } </style > </head > <body > <div class ="container" > <div class ="row" > <div class ="col-md-3 col-sm-6 pink" > <div class ="row" > <div class ="col-lg-6 orange" > FIRST HALF</div > <div class ="col-lg-6 orange" > OTHER HALF</div > </div > </div > <div class ="col-md-3 col-sm-6 pink" > TOUR DATE!</div > <div class ="col-md-3 col-sm-6 pink" > TOUR DATE!</div > <div class ="col-md-3 col-sm-6 pink" > <div class ="row" > <div class ="col-lg-2 orange" > </div > <div class ="col-lg-2 orange" > </div > <div class ="col-lg-2 orange" > </div > <div class ="col-lg-2 orange" > </div > <div class ="col-lg-2 orange" > </div > <div class ="col-lg-2 orange" > </div > </div > </div > </div > </div > <script src ="https://code.jquery.com/jquery-2.2.4.js" integrity ="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin ="anonymous" > </script > <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity ="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin ="anonymous" > </script > </body > </html >
grid实战
实战
使用了fontawesome。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 <!DOCTYPE html> <html > <head > <title > Bootstrap Navbars</title > <link rel ="stylesheet" type ="text/css" href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" > <link rel ="stylesheet" href ="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity ="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin ="anonymous" > <style type ="text/css" > body { padding-top : 70px ; } </style > </head > <body > <nav class ="navbar navbar-inverse navbar-fixed-top" > <div class ="container" > <div class ="navbar-header" > <button type ="button" class ="navbar-toggle collapsed" data-toggle ="collapse" data-target ="#bs-nav-demo" aria-expanded ="false" > <span class ="sr-only" > Toggle navigation</span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > </button > <a href ="#" class ="navbar-brand" > <span class ="glyphicon glyphicon-picture" > </span > IMGS</a > </div > <div class ="collapse navbar-collapse" id ="bs-nav-demo" > <ul class ="nav navbar-nav" > <li > <a href ="#" > About</a > </li > <li > <a href ="#" > Contact</a > </li > </ul > <ul class ="nav navbar-nav navbar-right" > <li > <a href ="#" > Sign Up</a > </li > <li > <a href ="#" > Login</a > </li > </ul > </div > </div > </nav > <div class ="container" > <div class ="jumbotron" > <h1 > <i class ="far fa-thumbs-up fa-2x" > </i > </span > The Image Gallery </h1 > <p > A bunch of beautiful images that I didn't take(except for the first one!)</p > </div > <div class ="row" > <div class ="col-lg-4 col-sm-6" > <div class =" " > <img src ="http://i.imgur.com/qK42fUu.jpg" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1439524970634-649c37a69e5c?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1450&h=825&fit=crop&s=bfda9916c885869b43b70738693428d9" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1444090542259-0af8fa96557e?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1434543177303-ef2cc7707e0d?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1436262513933-a0b06755c784?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1439396087961-98bc12c21176?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > <div class ="col-lg-4 col-sm-6" > <div class ="thumbnail" > <img src ="https://images.unsplash.com/photo-1439694458393-78ecf14da7f9?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" > </div > </div > </div > <script src ="https://code.jquery.com/jquery-2.1.4.js" > </script > <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" > </script > </body > </html >
实战2
实战2
unsplash图片:https://unsplash.com
获取图片url:https://source.unsplash.com/lQ3go6MNPzo
使用了fontawesome。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 <!DOCTYPE html> <html > <head > <title > Purrfect Match</title > <link rel ="stylesheet" type ="text/css" href ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" > <link rel ="stylesheet" type ="text/css" href ="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" > <link href ="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel ="stylesheet" type ="text/css" > <meta name ="viewport" content ="width=device-width, initial-scale=1" > <style type ="text/css" > body { background: url(https://images.unsplash.com/photo-1415369629372-26f2fe60c467); background-size: cover; background-position: center; } body, html { width: 100%; height: 100%; font-family: "Lato"; color: white; } h1 { font-weight: 700; font-size: 5em; } .content { padding-top: 25%; text-align: center; text-shadow : 0px 4px 3px rgba (0,0,0,0.4 ), 0px 8px 13px rgba (0,0,0,0.1 ), 0px 18px 23px rgba (0,0,0,0.1 ); } hr { max-width: 90%; width: 400px; border-top : 1px solid #f8f8f8 ; border-bottom : 1px solid rgba (0,0,0,0.2 ); } </style > </head > <body > <nav class ="navbar navbar-default navbar-fixed-top" > <div class ="container" > <div class ="navbar-header" > <button type ="button" class ="navbar-toggle collapsed" data-toggle ="collapse" data-target ="#navbar" aria-expanded ="false" aria-controls ="navbar" > <span class ="sr-only" > Toggle navigation</span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > <span class ="icon-bar" > </span > </button > <a class ="navbar-brand" href ="#" > Purrfect Match</a > </div > <div id ="navbar" class ="collapse navbar-collapse" > <ul class ="nav navbar-nav" > <li class ="active" > <a href ="#" > Home</a > </li > <li > <a href ="#about" > About</a > </li > <li > <a href ="#contact" > Contact</a > </li > </ul > <ul class ="nav navbar-nav navbar-right" > <li > <a href ="#" > Signup <i class ="fa fa-user-plus" > </i > </a > </li > <li > <a href ="#about" > Login <i class ="fa fa-user" > </i > </a > </li > </ul > </div > </div > </nav > <div class ="container" > <div class ="row" > <div class ="col-lg-12" > <div class ="content" > <h1 > Purrfect Match</h1 > <h3 > The Only Human-Feline Dating App</h3 > <hr > <button class ="btn btn-default btn-lg" > <i class ="fa fa-paw fa-fw" > </i > Get Started!</button > </div > </div > </div > </div > <script type ="text/javascript" src ="https://code.jquery.com/jquery-2.1.4.js" > </script > <script type ="text/javascript" src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" > </script > </body > </html > `
bootstrap4
bootstrap4 相对于bootstrap3的改变:https://getbootstrap.com/docs/4.2/migration/
第一个bootstrap程序
测试导入的css与js库是否成功:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Hello, world!</title > </head > <body > <h1 > Hello, world!</h1 > <div class ="card" style ="width: 18rem;" > <div class ="card-body" > <h5 class ="card-title" > Card title</h5 > <h6 class ="card-subtitle mb-2 text-muted" > Card subtitle</h6 > <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 ="card-link" > Card link</a > <a href ="#" class ="card-link" > Another link</a > </div > </div > <div class ="dropdown" > <button class ="btn btn-secondary dropdown-toggle" type ="button" id ="dropdownMenuButton" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown button </button > <div class ="dropdown-menu" aria-labelledby ="dropdownMenuButton" > <a class ="dropdown-item" href ="#" > Action</a > <a class ="dropdown-item" href ="#" > Another action</a > <a class ="dropdown-item" href ="#" > Something else here</a > </div > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
颜色
颜色,包含了背景颜色与字体颜色:https://getbootstrap.com/docs/4.2/utilities/colors/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Colors</title > </head > <body > <div class ="container" > <h1 class ="text-primary" > I am an h1</h1 > <h1 class ="text-danger" > I am an h1</h1 > <h1 class ="text-info" > I am an h1</h1 > <h1 class ="text-success" > I am an h1</h1 > <h1 class ="text-warning" > I am an h1</h1 > <h1 class ="text-white bg-dark" > I am an h1</h1 > <h1 class ="text-success" > I am an h1</h1 > <h1 class ="bg-light" > I am an h1</h1 > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
排版
1、 bootstrap4增加了display class
2、rem的基准从bootstrap3 中的14px变到了bootstrap4中的16px。
3、bootstrap3中 引言为标签,变为了class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Typography</title > </head > <body > <div class ="container" > <h1 > Regular H1</h1 > <h1 class ="display-1 text-info" > Display 1</h1 > <h1 class ="display-2" > Display 2</h1 > <h1 class ="display-3" > Display 3</h1 > <h1 class ="display-4" > Display 4</h1 > <blockquote > <p class ="mb-0" > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p > </blockquote > <blockquote class ="blockquote" > <p class ="mb-0" > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p > </blockquote > <blockquote class ="blockquote" > <p class ="mb-0" > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p > <footer class ="blockquote-footer" > Written by my cat <cite title ="Blue Steele" > Blue Steele</cite > </footer > </blockquote > <blockquote class ="blockquote text-right" > <p class ="mb-0" > Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p > <footer class ="blockquote-footer" > Written by my cat <cite title ="Blue Steele" > Blue Steele</cite > </footer > </blockquote > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
boder padding and margin
边框的颜色可以任意的设置颜色、设置是否有边框
边框:https://getbootstrap.com/docs/4.2/utilities/borders/
padding and margin均可任意设置上下左右 margin与padding的有无与大小
padding and margin:https://getbootstrap.com/docs/4.2/utilities/spacing/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Utilities</title > </head > <body > <div class ="container" > <h1 class ="text-center display-1" > Utilities</h1 > <h5 class ="border border-danger rounded-top" > GIVE ME A BORDER</h5 > <h5 class ="border-top border-info" > GIVE ME A BORDER</h5 > <h5 class ="border border-left-0 border-warning" > GIVE ME A BORDER</h5 > <button class ="btn btn-info p-0" > P0</button > <button class ="btn btn-info p-1" > P1</button > <button class ="btn btn-info p-2" > P2</button > <button class ="btn btn-info p-3" > P3</button > <button class ="btn btn-info p-4" > P4</button > <button class ="btn btn-info p-5" > P5</button > <button class ="btn btn-info pt-5" > Pt-5</button > <button class ="btn btn-info pb-5" > Pb-5</button > <button class ="btn btn-info py-5" > Py-5</button > <button class ="btn btn-info pl-5" > Pl-5</button > <button class ="btn btn-info pr-5" > Pr-5</button > <button class ="btn btn-info px-5" > Px-5</button > <p class ="bg-success text-white m-0" > I AM M-0</p > <p class ="bg-success text-white m-1" > I AM M-1</p > <p class ="bg-success text-white m-2" > I AM M-2</p > <p class ="bg-success text-white m-3" > I AM M-3</p > <p class ="bg-success text-white m-4" > I AM M-4</p > <p class ="bg-success text-white m-5" > I AM M-5</p > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
breakpoints 与 padding margin 混合使用
bootstrap4有5个breakpoints:https://getbootstrap.com/docs/4.2/layout/overview/
分别为:xs(最小,一般不写),sm,md,lg,xl
breakpoints 与 padding margin 混合使用:
{property}{sides}-{breakpoint}-{size}
padding and margin:https://getbootstrap.com/docs/4.2/utilities/spacing/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Breakpoints</title > </head > <body > <div class ="container text-center" > <h1 class ="display-3" > Breakpoints</h1 > <button class ="btn btn-warning p-sm-5 p-md-0 p-lg-5 p-xl-0" > BUTTON</button > <button class ="btn btn-danger p-0 p-sm-2 p-md-3 p-lg-4 p-xl-5" > BUTTON</button > <button class ="btn btn-success p-0 pl-sm-5 pt-md-5 pr-lg-5 pb-xl-5" > BUTTON</button > <h1 > Margin Example</h1 > <button class ="btn btn-primary p-4 mx-0 mx-sm-2 mx-md-3 mx-lg-4 mx-xl-5" > Hi</button > <button class ="btn btn-primary p-4 mx-0 mx-sm-2 mx-md-3 mx-lg-4 mx-xl-5" > Hi</button > <button class ="btn btn-primary p-4 mx-0 mx-sm-2 mx-md-3 mx-lg-4 mx-xl-5" > Hi</button > <button class ="btn btn-primary p-4 mx-0 mx-sm-2 mx-md-3 mx-lg-4 mx-xl-5" > Hi</button > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
导航栏
相对于bootstrap3,导航兰增加了breakpoint,navbar-expand-XX根据分辨率不同发生不同的变化。
下面列出了不同分辨率的导航栏,在浏览器中去尝试!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Navbars</title > </head > <body > <div class ="container" > <h1 class ="text-center display-3" > Navbars</h1 > </div > <nav class ="navbar navbar-expand-sm navbar-light bg-light" > <a class ="navbar-brand" href ="#" > Expands at SM</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > Home <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item dropdown" > <a class ="nav-link dropdown-toggle" href ="#" id ="navbarDropdown" role ="button" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown </a > <div class ="dropdown-menu" aria-labelledby ="navbarDropdown" > <a class ="dropdown-item" href ="#" > Action</a > <a class ="dropdown-item" href ="#" > Another action</a > <div class ="dropdown-divider" > </div > <a class ="dropdown-item" href ="#" > Something else here</a > </div > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <form class ="form-inline my-2 my-lg-0" > <input class ="form-control mr-sm-2" type ="search" placeholder ="Search" aria-label ="Search" > <button class ="btn btn-outline-success my-2 my-sm-0" type ="submit" > Search</button > </form > </div > </nav > <nav class ="navbar navbar-expand-md navbar-light bg-light" > <a class ="navbar-brand" href ="#" > Expands at MD</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > Home <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item dropdown" > <a class ="nav-link dropdown-toggle" href ="#" id ="navbarDropdown" role ="button" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown </a > <div class ="dropdown-menu" aria-labelledby ="navbarDropdown" > <a class ="dropdown-item" href ="#" > Action</a > <a class ="dropdown-item" href ="#" > Another action</a > <div class ="dropdown-divider" > </div > <a class ="dropdown-item" href ="#" > Something else here</a > </div > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <form class ="form-inline my-2 my-lg-0" > <input class ="form-control mr-sm-2" type ="search" placeholder ="Search" aria-label ="Search" > <button class ="btn btn-outline-success my-2 my-sm-0" type ="submit" > Search</button > </form > </div > </nav > <nav class ="navbar navbar-expand-lg navbar-light bg-light" > <a class ="navbar-brand" href ="#" > Expands at LG</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > Home <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item dropdown" > <a class ="nav-link dropdown-toggle" href ="#" id ="navbarDropdown" role ="button" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown </a > <div class ="dropdown-menu" aria-labelledby ="navbarDropdown" > <a class ="dropdown-item" href ="#" > Action</a > <a class ="dropdown-item" href ="#" > Another action</a > <div class ="dropdown-divider" > </div > <a class ="dropdown-item" href ="#" > Something else here</a > </div > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <form class ="form-inline my-2 my-lg-0" > <input class ="form-control mr-sm-2" type ="search" placeholder ="Search" aria-label ="Search" > <button class ="btn btn-outline-success my-2 my-sm-0" type ="submit" > Search</button > </form > </div > </nav > <nav class ="navbar navbar-expand-xl navbar-light bg-light" > <a class ="navbar-brand" href ="#" > Expands at XL</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > Home <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item dropdown" > <a class ="nav-link dropdown-toggle" href ="#" id ="navbarDropdown" role ="button" data-toggle ="dropdown" aria-haspopup ="true" aria-expanded ="false" > Dropdown </a > <div class ="dropdown-menu" aria-labelledby ="navbarDropdown" > <a class ="dropdown-item" href ="#" > Action</a > <a class ="dropdown-item" href ="#" > Another action</a > <div class ="dropdown-divider" > </div > <a class ="dropdown-item" href ="#" > Something else here</a > </div > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <form class ="form-inline my-2 my-lg-0" > <input class ="form-control mr-sm-2" type ="search" placeholder ="Search" aria-label ="Search" > <button class ="btn btn-outline-success my-2 my-sm-0" type ="submit" > Search</button > </form > </div > </nav > <nav class ="navbar navbar-expand-xl navbar-dark bg-info" > <a class ="navbar-brand" href ="#" > Navbar-Dark</a > <button class ="navbar-toggler" type ="button" data-toggle ="collapse" data-target ="#navbarSupportedContent" aria-controls ="navbarSupportedContent" aria-expanded ="false" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navbarSupportedContent" > <ul class ="navbar-nav mr-auto" > <li class ="nav-item active" > <a class ="nav-link" href ="#" > Home <span class ="sr-only" > (current)</span > </a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > </div > </nav > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
display 隐藏与显示 结合breakpoint
还可以设置inline 与 block :https://getbootstrap.com/docs/4.2/utilities/display/
在浏览器中拖动大小显示效果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Display</title > </head > <body > <div class ="container" > <h1 class ="text-center display-4" > Display Utility</h1 > <h1 class ="border border-danger d-inline" > HELLO</h1 > <span class ="border border-success d-block" > HELLO</span > <h1 class ="d-xl-none" > HIDE ME ON XL</h1 > <h1 class ="d-none d-lg-block d-xl-none" > ALWAYS HIDDEN EXCEPT LG</h1 > </div > <div class ="container" > <div class ="jumbotron" > <h1 class ="display-4" > Hello, world!</h1 > <p class ="lead d-none d-md-block" > Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quis odio debitis voluptatem possimus corrupti labore alias! Ad ipsa, veniam in quo a aperiam obcaecati quae. Blanditiis delectus, corrupti optio voluptatem eum deserunt officiis vitae. Similique amet facere voluptas velit maxime neque, quisquam exercitationem aliquam vitae inventore cumque ad nihil sit expedita fugiat at, quos quae. Aperiam obcaecati aut magni veritatis!</p > <hr class ="my-4" > <p > It uses utility classes for typography and spacing to space content out within the larger container.</p > <a class ="btn btn-primary btn-lg" href ="#" role ="button" > Learn more</a > </div > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
flexBox
https://getbootstrap.com/docs/4.2/utilities/flex/
flexBox在布局的时候非常有用。
d-flex声明盒子是一个flexbox
flex-row表明盒子上下扩展
flex-column表明盒子左右扩展
flex-column-reverse、flex-row-reverse 镜像反转。
justify-content-start原本大小,不扩展 主坐标轴的排列
align-items-end 、justify-content-between、justify-content-around排列位置,这是次坐标轴的排列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Flexbox</title > </head > <body > <div class ="container" > <h1 class ="text-center display-4" > Flexbox</h1 > <div class ="border border-dark d-flex flex-row justify-content-start align-items-end" style ="height: 200px" > <button class ="btn btn-info btn-lg" > LARGE</button > <button class ="btn btn-primary" > SMALL</button > <button class ="btn btn-warning" > SMALL</button > </div > <div class ="border border-dark d-flex flex-row-reverse justify-content-start align-items-end" style ="height: 200px" > <button class ="btn btn-info btn-lg" > LARGE</button > <button class ="btn btn-primary" > SMALL</button > <button class ="btn btn-warning" > SMALL</button > </div > <div class ="border border-dark d-flex flex-column justify-content-start align-items-end" style ="height: 200px" > <button class ="btn btn-info btn-lg" > LARGE</button > <button class ="btn btn-primary" > SMALL</button > <button class ="btn btn-warning" > SMALL</button > </div > <div class ="border border-dark d-flex flex-column-reverse justify-content-start align-items-end" style ="height: 200px" > <button class ="btn btn-info btn-lg" > LARGE</button > <button class ="btn btn-primary" > SMALL</button > <button class ="btn btn-warning" > SMALL</button > </div > <h1 class ="display-4 text-center" > EXAMPLE TIME</h1 > <div class ="d-flex flex-column flex-md-row justify-content-between" > <button class ="btn btn-dark btn-lg" > Link 1</button > <button class ="btn btn-dark btn-lg" > Link 2</button > <button class ="btn btn-dark btn-lg" > Link 3</button > <button class ="btn btn-dark btn-lg" > Link 4</button > <button class ="btn btn-dark btn-lg" > Link 5</button > <button class ="btn btn-dark btn-lg" > Link 6</button > </div > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
NAV + flexBox
1、NAV相对于bootstrap3做了分离:
Instead of HTML-specific selectors like .nav > li > a, we use separate classes for .navs, .nav-items, and .nav-links. This makes your HTML more flexible while bringing along increased extensibility.
2、NAV默认是flexbox。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Navs</title > </head > <body > <div class ="container" > <h1 class ="text-center display-4" > Navs+Flex</h1 > <ul class ="nav border border-primary justify-content-around" > <li class ="nav-item" > <a class ="nav-link active" href ="#" > Active</a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <ul class ="nav nav-tabs mt-5 " > <li class ="nav-item" > <a class ="nav-link active" href ="#" > Active</a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item" > <a class ="nav-link" href ="#" > Link</a > </li > <li class ="nav-item" > <a class ="nav-link disabled" href ="#" > Disabled</a > </li > </ul > <nav class ="nav flex-column flex-sm-row justify-content-center align-items-center" > <a class ="nav-link active" href ="#" > Active</a > <a class ="nav-link" href ="#" > Link</a > <a class ="nav-link" href ="#" > Link</a > <a class ="nav-link disabled" href ="#" > Disabled</a > </nav > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
bootstrap4 grid
https://getbootstrap.com/docs/4.2/migration/#grid-system
增加了极小的屏幕xs, sm, md, lg, and xl.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > The Grid</title > </head > <body > <div class ="container" > <h1 class ="text-center display-4" > The Grid</h1 > <div class ="row border border-danger" > <h3 class ="col-sm-6 col-xl-3 bg-info m-0" > THING 1</h3 > <h3 class ="col-sm-6 col-xl-9 bg-warning m-0" > THING 2</h3 > </div > <div class ="row my-5" > <div class ="col bg-primary" > THING</div > <div class ="col-6 bg-info" > THING</div > <div class ="col bg-success" > THING</div > </div > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
案例1
效果图
首先nav-bar 以及jumbotron
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <link rel ="stylesheet" href ="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity ="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin ="anonymous" > <title > Pattern</title > <style type ="text/css" > #header { background: url(imgs/header.jpeg) center center / cover no-repeat; } </style > </head > <body > <nav class ="navbar bg-dark navbar-dark" > <div class ="container" > <a href ="" class ="navbar-brand" > <i class ="fas fa-binoculars mr-2" > </i > Pattern</a > </div > </nav > <section id ="header" class ="jumbotron text-center" > <h1 class ="display-3" > PATTERN</h1 > <p class ="lead" > Lorem ipsum dolor sit, amet consectetur adipisicing elit. Maiores, pariatur?</p > <a href ="" class ="btn btn-primary" > Do Something</a > <a href ="" class ="btn btn-success" > Another Thing</a > </section > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
接着加入gird以及card
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <link rel ="stylesheet" href ="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity ="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin ="anonymous" > <style > #header { background: url("imgs/header.jpeg"); } </style > <title > Pattern</title > </head > <body > <nav class ="navbar bg-dark navbar-dark" > <div class ="container" > <a href ="" class ="navbar-brand" > <i class ="fas fa-binoculars mr-2" > </i > Pattern</a > </div > </nav > <section id ="header" class ="jumbotron text-center" > <h1 class ="display-3" > PATTERN</h1 > <p class ="lead" > Lorem ipsum dolor sit, amet consectetur adipisicing elit. Maiores, pariatur?</p > <a href ="" class ="btn btn-primary" > Do Something</a > <a href ="" class ="btn btn-success" > Another Thing</a > </section > <section id ="gallery" > <div class ="container" > <div class ="row" > <div class ="col-lg-4 mb-4" > <div class ="card" > <img class ="card-img-top" src ="imgs/pattern1.jpeg" alt ="" > <div class ="card-body" > <h5 class ="card-title" > First Thing</h5 > <p class ="card-text" > Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda corrupti quam magnam! Veniam, dolorum facere? Commodi, ut. Et, itaque quam!</p > <a href ="" class ="btn btn-outline-success btn-sm" > Download</a > <a href ="" class ="btn btn-outline-danger btn-sm" > <i class ="far fa-heart" > </i > </a > </div > </div > </div > <div class ="col-lg-4 mb-4" > <div class ="card" > <img class ="card-img-top" src ="imgs/pattern2.jpeg" alt ="" > <div class ="card-body" > <h5 class ="card-title" > First Thing</h5 > <p class ="card-text" > Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda corrupti quam magnam! Veniam, dolorum facere? Commodi, ut. Et, itaque quam!</p > <a href ="" class ="btn btn-outline-success btn-sm" > Download</a > <a href ="" class ="btn btn-outline-danger btn-sm" > <i class ="far fa-heart" > </i > </a > </div > </div > </div > <div class ="col-lg-4 mb-4" > <div class ="card" > <img class ="card-img-top" src ="imgs/pattern3.jpeg" alt ="" > <div class ="card-body" > <h5 class ="card-title" > First Thing</h5 > <p class ="card-text" > Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda corrupti quam magnam! Veniam, dolorum facere? Commodi, ut. Et, itaque quam!</p > <a href ="" class ="btn btn-outline-success btn-sm" > Download</a > <a href ="" class ="btn btn-outline-danger btn-sm" > <i class ="far fa-heart" > </i > </a > </div > </div > </div > </div > </div > </section > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
flex+ grid
grid是一个flex盒子,其部件可以随意移动。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <title > Grid + Flexbox</title > </head > <body > <div class ="container" > <h1 class ="text-center display-4" > Grid + Flexbox</h1 > <div class ="row border justify-content-around align-items-center" > <div class ="col-sm-3 bg-warning" > Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem culpa et tempora corporis? Tempora commodi perspiciatis omnis quos ex similique! </div > <div class ="col-sm-3 bg-info" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Blanditiis tempore minus ad ab, explicabo voluptatem officia. Voluptas sed odio nemo, nostrum cumque dolorem quam, repellat nam porro ex aperiam, ipsa eveniet numquam cupiditate sapiente esse fugiat? Et tempora eveniet inventore voluptates magnam obcaecati quasi, at, consectetur adipisci natus sunt blanditiis. </div > <div class ="col-sm-3 bg-warning" > Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem culpa et tempora corporis? Tempora commodi perspiciatis omnis quos ex similique! </div > </div > <div class ="row border justify-content-center align-items-end" > <div class ="col-2 bg-primary align-self-start" > Lorem ipsum dolor, sit amet consectetur adipisicing elit. Minus, non. </div > <div class ="col-2 bg-primary" > Lorem ipsum dolor, sit amet consectetur adipisicing elit. Minus, non. </div > <div class ="col-2 bg-success" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Quis perspiciatis earum eius saepe sint, laudantium deleniti, accusantium fugiat aut illo ab consequatur quos fuga aliquid facilis magni sed voluptates impedit! </div > <div class ="col-2 bg-primary align-self-start" > Lorem ipsum dolor, sit amet consectetur adipisicing elit. Minus, non. </div > <div class ="col-2 bg-primary" > Lorem ipsum dolor, sit amet consectetur adipisicing elit. Minus, non. </div > </div > <div class ="row text-center justify-content-between" > <div class ="col-md-6 col-lg-5 bg-danger" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Hic fugit quisquam libero distinctio blanditiis, error quos architecto velit aut atque. </div > <div class ="col-md-6 col-lg-5 bg-danger" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Hic fugit quisquam libero distinctio blanditiis, error quos architecto velit aut atque. </div > </div > </div > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
案例二
效果图
添加导航栏
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link href ="https://fonts.googleapis.com/css?family=Nunito:200,300,400,700" rel ="stylesheet" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <link rel ="stylesheet" href ="app.css" > <title > Museum of Candy</title > <style type ="text/css" > body { background : #f5d9d5 ; font-family: "Nunito", sans-serif; } #mainNavbar { font-size : 1.5rem ; font-weight: 100; } #mainNavbar .nav-link { color: white; } #mainNavbar .nav-link :hover { color : #EA1C2C ; } #mainNavbar .navbar-brand { color : #EA1C2C ; font-size : 1.5rem ; } </style > </head > <body > <nav id ="mainNavbar" class ="navbar navbar-dark navbar-expand-md py-0 fixed-top" > <a href ="#" class ="navbar-brand" > CANDY</a > <button class ="navbar-toggler" data-toggle ="collapse" data-target ="#navLinks" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navLinks" > <ul class ="navbar-nav" > <li class ="nav-item" > <a href ="" class ="nav-link" > HOME</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > ABOUT</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > TICKETS</a > </li > </ul > </div > </nav > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link href ="https://fonts.googleapis.com/css?family=Nunito:200,300,400,700" rel ="stylesheet" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <link rel ="stylesheet" href ="app.css" > <title > Museum of Candy</title > <style type ="text/css" > body { background : #f5d9d5 ; font-family: "Nunito", sans-serif; } #mainNavbar { font-size : 1.5rem ; font-weight: 100; } #mainNavbar .nav-link { color: white; } #mainNavbar .nav-link :hover { color : #EA1C2C ; } #mainNavbar .navbar-brand { color : #EA1C2C ; font-size : 1.5rem ; } #headingGroup span { color : #EA1C2C ; } #headingGroup h1 { font-weight: 100; font-size: 4rem; } @media (max-width: 1200px ) { #headingGroup h1 { font-weight: 100; font-size: 3rem; } } </style > </head > <body > <nav id ="mainNavbar" class ="navbar navbar-dark navbar-expand-md py-0 fixed-top" > <a href ="#" class ="navbar-brand" > CANDY</a > <button class ="navbar-toggler" data-toggle ="collapse" data-target ="#navLinks" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navLinks" > <ul class ="navbar-nav" > <li class ="nav-item" > <a href ="" class ="nav-link" > HOME</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > ABOUT</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > TICKETS</a > </li > </ul > </div > </nav > <section class ="container-fluid px-0" > <div class ="row align-items-center" > <div class ="col-lg-6" > <div id ="headingGroup" class ="text-white text-center d-none d-lg-block mt-5" > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > </div > </div > <div class ="col-lg-6" > <img class ="img-fluid" src ="imgs/hand2.png" alt ="" > </div > </div > </section > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
内容2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 <!doctype html> <html lang ="en" > <head > <meta charset ="utf-8" > <meta name ="viewport" content ="width=device-width, initial-scale=1, shrink-to-fit=no" > <link href ="https://fonts.googleapis.com/css?family=Nunito:200,300,400,700" rel ="stylesheet" > <link rel ="stylesheet" href ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity ="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin ="anonymous" > <link rel ="stylesheet" href ="app.css" > <title > Museum of Candy</title > <style type ="text/css" > body { background : #f5d9d5 ; font-family: "Nunito", sans-serif; } #mainNavbar { font-size : 1.5rem ; font-weight: 100; } #mainNavbar .nav-link { color: white; } #mainNavbar .nav-link :hover { color : #EA1C2C ; } #mainNavbar .navbar-brand { color : #EA1C2C ; font-size : 1.5rem ; } #headingGroup span { color : #EA1C2C ; } #headingGroup h1 { font-weight: 100; font-size: 4rem; } .content { margin-top: 100px; margin-bottom: 100px; } .blurb h2 { color : #EA1C2C ; font-weight: 100; font-size : 2.5rem ; } .blurb p { color : #f498b8 ; font-weight: 100; font-size : 1.125rem ; line-height: 2; } @media (max-width: 1200px ) { #headingGroup h1 { font-weight: 100; font-size: 3rem; } } </style > </head > <body > <nav id ="mainNavbar" class ="navbar navbar-dark navbar-expand-md py-0 fixed-top" > <a href ="#" class ="navbar-brand" > CANDY</a > <button class ="navbar-toggler" data-toggle ="collapse" data-target ="#navLinks" aria-label ="Toggle navigation" > <span class ="navbar-toggler-icon" > </span > </button > <div class ="collapse navbar-collapse" id ="navLinks" > <ul class ="navbar-nav" > <li class ="nav-item" > <a href ="" class ="nav-link" > HOME</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > ABOUT</a > </li > <li class ="nav-item" > <a href ="" class ="nav-link" > TICKETS</a > </li > </ul > </div > </nav > <section class ="container-fluid px-0" > <div class ="row align-items-center" > <div class ="col-lg-6" > <div id ="headingGroup" class ="text-white text-center d-none d-lg-block mt-5" > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > <h1 class ="" > MUSEUM<span > /</span > OF<span > /</span > CANDY</h1 > </div > </div > <div class ="col-lg-6" > <img class ="img-fluid" src ="imgs/hand2.png" alt ="" > </div > </div > <div class ="row align-items-center content" > <div class ="col-md-6 text-center" > <div class ="row justify-content-center" > <div class ="col-10 col-lg-8 blurb mb-5 mb-md-0" > <h2 > MUSEUM OF CANDY</h2 > <img src ="imgs/lolli_icon.png" alt ="" class ="d-none d-lg-inline" > <p class ="lead" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae beatae, maiores deserunt in voluptatibus aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur repellat eveniet quidem voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam autem nam ex deserunt debitis eaque ratione! Nobis, quidem assumenda.</p > </div > </div > </div > <div class ="col-md-6" > <img src ="imgs/gumball.png" alt ="" class ="img-fluid" > </div > </div > <div class ="row align-items-center content" > <div class ="col-md-6 order-2 order-md-1" > <img src ="imgs/sprinkles.png" alt ="" class ="img-fluid" > </div > <div class ="col-md-6 text-center order-1 order-md-2" > <div class ="row justify-content-center" > <div class ="col-10 col-lg-8 blurb mb-5 mb-md-0" > <h2 > MUSEUM OF CANDY</h2 > <img src ="imgs/lolli_icon.png" alt ="" class ="d-none d-lg-inline" > <p class ="lead" > Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, iste molestiae beatae, maiores deserunt in voluptatibus aspernatur architecto excepturi delectus soluta? Ipsa, deleniti dolorem hic consequatur repellat eveniet quidem voluptate necessitatibus dolorum delectus minus vitae, ut, veritatis sint ipsum magnam autem nam ex deserunt debitis eaque ratione! Nobis, quidem assumenda.</p > </div > </div > </div > </div > </section > <script src ="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity ="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin ="anonymous" > </script > <script src ="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity ="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin ="anonymous" > </script > <script src ="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity ="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin ="anonymous" > </script > </body > </html >
添加js
当页面滑动时,导航栏换颜色