根据上一章博客我们讲解了Bootstrap的安装
这一章来讲解一下12栅格系统 排版等等
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
.row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
}
style>
<body>
<div class="container">
<div class="row">
<div class="col-md-4" >第一行:.col-md-4div>
<div class="col-md-8">第一行:.col-md-8div>
div>
<div class="row">
<div class="col-md-2">第二行:.col-md-2div>
<div class="col-md-10">第二行:.col-md-10div>
div>
<div class="row">
<div class="col-md-6">第三行:.col-md-6div>
<div class="col-md-6">第三行:.col-md-6div>
div>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
.row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
}
style>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-1" >第一行:.col-md-4div>
<div class="col-md-8">第一行:.col-md-8div>
div>
<div class="row">
<div class="col-md-2 col-md-offset-1">第二行:.col-md-2div>
<div class="col-md-4 col-md-offset-1">第二行:.col-md-4div>
div>
<div class="row">
<div class="col-md-10 col-md-offset-1">第三行:.col-md-10div>
<div class="col-md-4">第三行:.col-md-4div>
div>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
.row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
}
style>
<body>
<div class="container">
<div class="row">
<div class="col-md-10">第一行:.col-md-10div>
<div class="col-md-2">第一行:.col-md-2div>
div>
<div class="row">
<div class="col-md-6">第二行:.col-md-6div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">1-1div>
<div class="col-md-6">1-2div>
div>
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">2-1div>
<div class="col-md-6">2-2div>
div>
div>
<div class="col-md-6">2-2div>
div>
div>
div>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
.row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
}
style>
<body>
<div class="container">
<div class="row">
<div class="col-md-10">第一行:.col-md-10div>
<div class="col-md-2">第一行:.col-md-2div>
div>
<div class="row">
<div class="col-md-4 col-md-push-1" >第二行:.col-md-4div>
<div class="col-md-4 col-md-pull-1">第二行:.col-md-4div>
div>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<div class="col-md-8 col-xs-12">
<h3>献给父亲身后默默支持的英雄h3>
<div class="row">
<ul class="col-md-6 col-xs-12">
<li>这是一首由董玉方作词,许飞作曲、演唱的歌曲li>
ul>
<ul class="col-md-6 col-xs-12">
省略部分HTML代码
div>
div>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<h1>我是h1h1>
<h2>我是h2h2>
<h3>我是h3h3>
<h4>我是h4h4>
<h5>我是h5h5>
<h6>我是h6h6>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<span class="h1">我是h1span><br/>
<span class="h2">我是h2span><br/>
<span class="h3">我是h3span><br/>
<span class="h4">我是h4span><br/>
<span class="h5">我是h5span><br/>
<span class="h6">我是h6span><br/>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
在非标题标签下使用 .h1 到 .h6 类的方式
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<div class="duiqi text-center">
居中
div><br>
<div class="duiqi text-left">
左对齐
div><br>
<div class="duiqi text-right">
右对齐
div><br>
<div class="duiqi text-justify">
两端对齐
div><br>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
通过文本对齐类,可以简单方便的将文字重新对齐
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<dl class="dileibiao dl-horizontal">
<dt>水果dt>
<dd>苹果、香蕉、橙子、西瓜、火龙果、猕猴桃dd>
<dt>咖啡dt>
<dd>速溶咖啡、拿铁、美式、摩卡dd>
<dt>茶叶dt>
<dd>红茶、绿茶、乌龙茶、黄茶、白茶、黑茶dd>
dl><br>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
水平定义列表
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<ul class="lileibiao list-inline text-center">
<li>HTMLli>
<li>CSSli>
<li>JavaScriptli>
<li>Bootstrapli>
ul>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
内联列表
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-inline" action="#">
<div class="form-group">
<label for="user">用户名:label>
<input type="text" class="form-control" id="user" placeholder="请输入用户名">
div>
<div class="form-group">
<label for="pwd">密码:label>
<input type="password" class="form-control" id="pwd" placeholder="请输入密码">
div>
<input type="submit" class="form-control" value="登录">
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
在表单的默认样式基础上给表单添加 .form-control 和.form-group
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-horizontal" action="#">
<div class="form-group">
<label for="user" class="col-md-1">用户名:label>
<div class="col-md-8">
<input type="text" class="form-control" id="user" placeholder="请输入用户名">
div>
div>
<div class="form-group">
<label for="pwd" class="col-md-1">密码:label>
<div class="col-md-8">
<input type="password" class="form-control" id="pwd" placeholder="请输入密码">
div>
div>
<div class="form-group">
<div class="col-md-offset-3 col-md-2">
<input type="submit" class="form-control" value="登录">
div>
div>
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
可以通过为表单添加 .form-horizontal ,并联合使用Bootstrap预置的栅格类,可以将文字和表单控件水平排列布局
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-horizontal" action="#">
<div class="form-group has-warning">
<label for="user" class="col-md-1">用户名:label>
<div class="col-md-8">
<input type="text" class="form-control" id="user" placeholder="请输入用户名">
div>
div>
<div class="form-group has-error">
<label for="pwd" class="col-md-1">密码:label>
<div class="col-md-8">
<input type="password" class="form-control" id="pwd" placeholder="请输入密码">
div>
div>
<div class="form-group">
<div class="col-md-offset-3 col-md-2">
<input type="submit" class="form-control" value="登录">
div>
div>
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
添加 .has-warning、.has-error 或 .has-success 到表单控件的父元素即可校验表单状态
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-horizontal" action="#">
<div class="form-group">
<input type="text" class="input-lg form-control" placeholder="大型输入框">
div>
<div class="form-group">
<input type="text" class="form-control" placeholder="正常输入框">
div>
<div class="form-group">
<input type="text" class="input-sm form-control" placeholder="小型输入框">
div>
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
通过.input-lg和.input-sm设置表单控件的尺寸
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-horizontal" action="#">
<button type="button" class="btn btn-default">(默认样式-灰色)Defaultbutton>
<button type="button" class="btn btn-primary">(首选项-深蓝色)Primarybutton>
<button type="button" class="btn btn-success">(成功-绿色)Successbutton>
<button type="button" class="btn btn-info">(一般信息-天蓝色)Infobutton>
<button type="button" class="btn btn-warning">(警告-黄色)Warningbutton>
<button type="button" class="btn btn-danger">(危险-红色)Dangerbutton>
<button type="button" class="btn btn-link">(链接)Linkbutton>
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
Bootstrap框架提供了七种样式的按钮风格
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<form class="form-horizontal" action="#">
<button type="button" class="btn btn-default">(默认样式-灰色)默认大小button>
<button type="button" class="btn btn-primary btn-lg">(首选项-深蓝色)大型按钮
button>
<button type="button" class="btn btn-success btn-sm">(成功-绿色)小型按钮
button>
<button type="button" class="btn btn-info btn-xs">(一般信息-天蓝色)超小型按钮
button>
form>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
可以通过.btn-lg、.btn-sm 或 .btn-xs实现按钮具有不同的尺寸
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<img src="../../淘宝/img/1231.png" class="img-responsive">
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bootstrap基础模板title>
<link rel="stylesheet" href="../css/bootstrap.min.css">
head>
<style>
/* .row{
border: 1px solid cadetblue;
}
.row>div{
border: 1px solid darkblue;
} */
style>
<body>
<div class="container">
<img src="../../淘宝/img/1231.png" class="img-rounded img-responsive" width="50%" alt=""><br>
<img src="../../淘宝/img/1231.png" class="img-circle img-responsive" width="50%" alt=""><br>
<img src="../../淘宝/img/1231.png" class="img-thumbnail img-responsive" width="50%" alt=""><br>
div>
body>
<script src="../js/jquery.js">script>
<script src="../js/bootstrap.min.js">script>
html>
为 元素添加.img-rounded、.img-circle、.img-thumbnail,可以让图片呈现不同的形状
送大家一句最喜欢比阿斯的短话: 要从容地着手去做一件事,但一旦开始,就要坚持到底。