BootStrap常用CSS样式的代码示例

Bootstrap常用的样式的代码示例


  1. 样式表引入的注意事项

jquery.js是bootstrap.js的基础,引入js文件时必须先引入jquery.js.
后引入jquery.js错误代码:Uncaught Error: Bootstrap's JavaScript requires jQuery

<head>
    <script src="jquery.js">script>
    <script src="bootstrap.js">script>
    <link rel="stylesheet" href="bootstrap.css">
head>

2.栅格系统

因为各种屏幕的尺寸不一样,为了实现自适应,将屏幕分成12等分,规定每个元素所占的等分个数来实现在自适应。

<body>
    <div class="container">
        <div class="row">
            <div class="col-md-1>1
col-md-2>2div> <div class="col-md-3>3
col-md-4>4div> <div class="col-md-2>2

BootStrap常用CSS样式的代码示例_第1张图片

3.Bootstrap表格样式

  • 最基础的样式
<table class="table">
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <td>d1td>
        <td>d2td>
        <td>d3td>
    tr>
table>

这里写图片描述

  • 带边框的表格
<table class="table table-bordered">
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <td>d1td>
        <td>d2td>
        <td>d3td>
    tr>
table>

BootStrap常用CSS样式的代码示例_第2张图片

  • 带条纹的表格
<table class="table table-bordered table-striped">
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>       
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>               
table>

BootStrap常用CSS样式的代码示例_第3张图片

  • 鼠标悬停表格
<table class ="table table-bordered table-hover">
    <tr>
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <td>d1td>
        <td>d2td>
        <td>d3td>
    tr>
table>

BootStrap常用CSS样式的代码示例_第4张图片

  • 状态类表格(带背景色的表格)
<table class ="table table-bordered table-hover">
    <tr class="active">
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr class="danger">
        <td>d1td>
        <td>d2td>
        <td>d3td>
    tr>
    <tr class="info">
        <th>h1th>
        <th>h2th>
        <th>h3th>
    tr>
    <tr>
        <td class="success">d1td>
        <td class="warning">d2td>
        <td class="success">d3td>
    tr>
table>

BootStrap常用CSS样式的代码示例_第5张图片

4.表单样式

表单元素一般使用.form-control来修饰,一组控件最好放在一个div.form-group中显得更紧凑。

  • 基本的表单
<form action="">
   <div class="form-group">
      <label for="name">namelabel>
      <input type="text" name="" id="name" class="form-control">
   div>
   <div class="form-group">
      <label for="password">passwordlabel>
      <input type="password" name="password" id="" class="form-control">
   div>
   <div class=" col-md-6 col-md-offset-3 form-group">
      <button class="btn btn-success">LOg inbutton>
      <button class="btn btn-warning">LogOUtbutton>
   div>
form>

BootStrap常用CSS样式的代码示例_第6张图片

  • 内联表单
    内联表单:在同一行的表单
<form action="" class="form-inline">
    <div class="form-group">
       <label for="name">用户名:label>
       <input type="text" name="" id="" class="form-control">
    div>
    <div class="form-group">
       <label for="password">密码:label>
       <input type="password" name="" id="" class="form-control">
    div>
    <div class="form-group">
       <button class="btn btn-success">LOG inbutton>
       <button class="btn btn-info">LOg outbutton>
    div>
form>

BootStrap常用CSS样式的代码示例_第7张图片

  • 水平排列的表单
<form action="" class="form-horizontal">
    <div class="form-group">
       <label for="name" class="col-md-2 control-label">Name:label>
    <div class="col-md-10">
        <input type="text" name="name" id="name" class="form-control">
    div>
    div>
    <div class="form-group">
        <label for="password" class="col-md-2 control-label">Password:label>
    <div class="col-md-10">
        <input type="password" name="password" id="password" class="form-control">
    div>
    div>
    <div class="form-group">
    <div class="col-md-6 col-md-offset-3">
        <button class="btn btn-success">登陆button>
        <button class="btn btn-warning">登出button>
    div>
    div>
form>

BootStrap常用CSS样式的代码示例_第8张图片

  • 支持多行文本的文本域
<textarea class="form-control" rows="3">textarea>

  • 单选框和多选框

    1.默认样式(独占一行)

<div class="checkbox">
    <label>
       <input type="checkbox" name="" id="">
       默认的多选框样式
    label>
div>
<div class="checkbox">
    <label>
       <input type="checkbox" name="" id="">
       默认的多选框样式
    label>
div>

<div class="radio">
   <label>
       <input type="radio" name="name" id="">
      默认的单选框样式
   label>
div>
<div class="radio">
   <label>
      <input type="radio" name="name" id="">
      默认的单选框样式
    label>
div>

BootStrap常用CSS样式的代码示例_第9张图片


2.内联多选框和单选框

<label class="checkbox-inline">
    <input type="checkbox" name="name" id="" class="form-control">1
label>
<label class="checkbox-inline">
    <input type="checkbox" name="name" id="" class="form-control">2
label>

<div>div>
<label class="radio-inline">
    <input type="radio" name="name2" id="" class="form-control">1
label>
<label class="radio-inline">
    <input type="radio" name="name2" id="" class="form-control">2
label>

BootStrap常用CSS样式的代码示例_第10张图片


  • 下拉列表
<select class="form-control">
    <option value="1">1option>
    <option value="2">2option>
    <option value="3">3option>
select>

这里写图片描述

  • 静态控件?
    没搞懂这个东西是干啥用的,也不知道 label.sr-only 是干嘛用的。
<div class="form-group">
    <label class="control-label col-md-2">Emaillabel>
    <div class="col-md-10">
        <p class="form-control-static">[email protected]p>
    div>
div>
<div class="form-group">
    <label class="control-label col-md-2 sr-only">Emaillabel>
    <div class="col-md-10">
        <p class="form-control-static">[email protected]p>
    div>
div>
![这里写图片描述](https://img-blog.csdn.net/20171018112947202?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzEzMzkzNjU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
  • 输入框几种状态

    @1.自动获得焦点状态

    看了半天文档没看懂,按照文档写了两遍,都不生效。Html5新增 autofocus 属性,刚好解决bootstrap自动获得焦点的问题。

<input type="text" class="form-control" autofocus>

BootStrap常用CSS样式的代码示例_第11张图片

@2.禁用状态和只读状态

<input type="text" disabled class="form-control" value="Hello">
<input type="text" readonly class="form-control" value="hello">

BootStrap常用CSS样式的代码示例_第12张图片
@3.批量禁用

Talk is cheap,show U code.

<form>
  <fieldset disabled>
      <input type="text" class="form-control">
      <input type="radio" class="form-control">
  fieldset>
form>

BootStrap常用CSS样式的代码示例_第13张图片

  • 一些样式组合

@1.带提示文档的输入框

<div class="form-group">
   <label for="input1" class="control-label ">Emaillabel>
   <input type="text" name="" id="input1" class="form-control">
   <span class="help-block">请输入电子邮件。span>
div>
<div class="form-group">
   <label for="input2" class="control-label">Namelabel>
   <input type="text" name="name" id="input2" class="form-control">
   <span class="help-block">请输入姓名。span>
div>

BootStrap常用CSS样式的代码示例_第14张图片

@2.校验状态

将整个.form-group加上色彩。

<div class="form-group has-error">
    <label for="input1" class="control-label">namelabel>
    <input type="text" name="name" id="input1" class="form-control">
div>

BootStrap常用CSS样式的代码示例_第15张图片

@ 3.带有额外的图标

<div class="form-group has-feedback">
   <label for="input1" class="control-label">Namelabel>
   <input type="text" name="name" id="input1" class="form-control">
   <span class="glyphicon glyphicon-ok form-control-feedback">span>
div>

BootStrap常用CSS样式的代码示例_第16张图片

<div class="form-group has-success has-feedback">
    <label for="input2" class="control-label">Namelabel>
    <div class="input-group">
        <span class="input-group-addon">@span>
        <input type="text" name="name" id="input2" class="form-control">
        <span class="glyphicon glyphicon-ok form-control-feedback">span>
    div>
div>

BootStrap常用CSS样式的代码示例_第17张图片

  • 控件尺寸


    @1.控件高度
<input class="form-control input-lg" type="text">
<input class="form-control" type="text">
<input class="form-control input-sm" type="text" >  

BootStrap常用CSS样式的代码示例_第18张图片

@2.控件宽度

<form class="form-horizontal">
  <div class="form-group form-group-lg">
    <label class="col-sm-2 control-label">Large labellabel>
    <div class="col-sm-10">
    <input class="form-control" type="text">
    div>
  div>
  <div class="form-group form-group-sm">
    <label class="col-sm-2 control-label">Small labellabel>
    <div class="col-sm-10">
    <input class="form-control" type="text">
    div>
  div>
form>

BootStrap常用CSS样式的代码示例_第19张图片

  • 按钮

样式类型 内容 示例
背景色 btn-default,btn-success,btn-info,btn-danger,btn-primary,btn-warning,btn-link
激活状态 active
链接
禁用状态 disabled

-

图片

@ 1.响应式图片

<img src="#" class="img-responsive">

@ 2.图片形状

<img src="#" class="img-rounded">
<img src="#" class="img-circle">
<img src="#" class="img-thumbnail">

BootStrap常用CSS样式的代码示例_第20张图片

  • 辅助类

@1. 文本颜色

<p class="text-muted">text-mutedp>
<p class="text-primary">text-primaryp>
<p class="text-success">text-successp>
<p class="text-info">text-infop>
<p class="text-warning">text-warningp>
<p class="text-danger">text-dangerp>

BootStrap常用CSS样式的代码示例_第21张图片

@2.文字背景颜色

<p class="bg-primary">bg-primaryp>
<p class="bg-success">bg-successp>
<p class="bg-info">bg-infop>
<p class="bg-warning">bg-warningp>
<p class="bg-danger">bg-dangerp>

BootStrap常用CSS样式的代码示例_第22张图片

  • 其他一些css样式

样式名称 样式类 样式代码 样式示例
关闭按钮 button.close>span>& times;
三角按钮 span.caret
快速浮动 div.pull-left/div.pull-right
内容块居中 div.center-block
清除浮动 div.clearfix
显示或者隐藏内容 .show/.hidden
*屏幕和键盘导航 .sr-only/.sr-only和.sr-only-foucusable配合使用
图片替换 .text-hide

Bootstrap CSS样式部分学习笔记到此结束

你可能感兴趣的:(web前端)