CMCC - Concetti Avanzati "CSS Framework, HTML5 e CSS3"

© 2014 - ALCA Società Cooperativa

CSS Frameworks

Obiettivi

Supporto a risoluzioni e dispositivi differenti

Supporto a risoluzioni e dispositivi differenti

Responsive Web Design

Responsive Web Design: come si ottiene?

Responsive Web Design: come si ottiene?

Responsive Web Design: CSS3 media queries

Progressive Enhancement

CSS Framework: cos'è?

Twitter Bootstrap

Introduzione a Bootstrap

Bootstrap: alcuni numeri

Bootstrap: perchè dovrei usarlo?

Bootstrap: browser support

Bootstrap: key features

Bootstrap: key features

La libreria Bootstrap è organizzata in tre macro-raggruppamenti:

Bootstrap: basic template

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <h1>Hello, world!</h1>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Bootstrap: grid system

Bootstrap: grid system

Bootstrap: grid template

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <h3>Tre colonne uguali</h3>
      <p>Ottieni 3 colonne di uguale larghezza <strong>sui desktop e su desktop grandi</strong>. Sui device mobile, sui tablet (e su risoluzioni inferiori) le colonne verranno automaticamente disposte in verticale.</p>
      <div class="row">
        <div class="col-md-4">.col-md-4</div>
        <div class="col-md-4">.col-md-4</div>
        <div class="col-md-4">.col-md-4</div>
      </div>
    </div>
  </body>
</html>

Bootstrap: grid template

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <h3>Tre colonne uguali</h3>
      <p>Ottieni 3 colonne di uguale larghezza <strong>su tutte le risoluzioni supportate</strong>
      <div class="row">
        <div class="col-xs-4">.col-xs-4</div>
        <div class="col-xs-4">.col-xs-4</div>
        <div class="col-xs-4">.col-xs-4</div>
      </div>
    </div>
  </body>
</html>

Bootstrap: grid template

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <h3>Mobile & Desktop</h3>
      <p>Le colonne hanno una larghezza iniziale del 50% sul mobile ed arrivano fino al 33.3% su un desktop</p>
      <div class="row">
        <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
        <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
        <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
      </div>
    </div>
  </body>
</html>

Bootstrap: typography

Bootstrap: gli header

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <h1>h1. Bootstrap heading <small>Testo secondario</small></h1>
      <h2>h2. Bootstrap heading <small>Testo secondario</small></h2>
      <h3>h3. Bootstrap heading <small>Testo secondario</small></h3>
      <h4>h4. Bootstrap heading <small>Testo secondario</small></h4>
      <h5>h5. Bootstrap heading <small>Testo secondario</small></h5>
      <h6>h6. Bootstrap heading <small>Testo secondario</small></h6>
    </div>
  </body>
</html>

Bootstrap: le tabelle

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <table class="table">
        <thead>
          <tr>
            <th>#</th>
            <th>Nome</th>
            <th>Cognome</th>
            <th>Username</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1</td>
            <td>Luca</td>
            <td>Greco</td>
            <td>@luca</td>
          </tr>
          <tr>
            <td>2</td>
            <td>Domenico</td>
            <td>Martella</td>
            <td>@domenico</td>
          </tr>
          <tr>
            <td>3</td>
            <td>The</td>
            <td>Bird</td>
            <td>@twitter</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>

Bootstrap: i forms

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <form role="form">
        <div class="form-group">
          <label for="exampleInputEmail1">Email</label>
          <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Inserisci una 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">Allega File</label>
          <input type="file" id="exampleInputFile">
          <p class="help-block">Qui ci andrebbe un messaggio di aiuto.</p>
        </div>
        <div class="checkbox">
          <label>
            <input type="checkbox"> Ricordami
          </label>
        </div>
        <button type="submit" class="btn btn-default">Invia</button>
      </form>
    </div>
  </body>
</html>

Bootstrap: i bottoni

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <!-- Standard button -->
      <button type="button" class="btn btn-default">Default</button>

      <!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
      <button type="button" class="btn btn-primary">Primary</button>

      <!-- Indicates a successful or positive action -->
      <button type="button" class="btn btn-success">Success</button>

      <!-- Contextual button for informational alert messages -->
      <button type="button" class="btn btn-info">Info</button>

      <!-- Indicates caution should be taken with this action -->
      <button type="button" class="btn btn-warning">Warning</button>

      <!-- Indicates a dangerous or potentially negative action -->
      <button type="button" class="btn btn-danger">Danger</button>

      <!-- Deemphasize a button by making it look like a link while maintaining button behavior -->
      <button type="button" class="btn btn-link">Link</button>
    </div>
  </body>
</html>

Bootstrap: le dimensioni dei bottoni

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <p>
        <button type="button" class="btn btn-primary btn-lg">Large button</button>
        <button type="button" class="btn btn-default btn-lg">Large button</button>
      </p>
      <p>
        <button type="button" class="btn btn-primary">Default button</button>
        <button type="button" class="btn btn-default">Default button</button>
      </p>
      <p>
        <button type="button" class="btn btn-primary btn-sm">Small button</button>
        <button type="button" class="btn btn-default btn-sm">Small button</button>
      </p>
      <p>
        <button type="button" class="btn btn-primary btn-xs">Extra small button</button>
        <button type="button" class="btn btn-default btn-xs">Extra small button</button>
      </p>
    </div>
  </body>
</html>

Bootstrap: i bottoni block-level

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <button type="button" class="btn btn-primary btn-lg btn-block">Block level button</button>
      <button type="button" class="btn btn-default btn-lg btn-block">Block level button</button>
    </div>
  </body>
</html>

Bootstrap: lo stato dei bottoni

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <button type="button" class="btn btn-lg btn-primary" disabled>Primary button (disabled)</button>
      <button type="button" class="btn btn-default btn-lg" disabled>Button (disabled)</button>
      <button type="button" class="btn btn-lg btn-primary">Primary button</button>
    </div>
  </body>
</html>

Bootstrap: le navbars

Bootstrap: le navbars

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
              <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>

          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Link</a></li>
              <li><a href="#">Link</a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
                  <li class="divider"></li>
                  <li><a href="#">Separated link</a></li>
                  <li class="divider"></li>
                  <li><a href="#">One more separated link</a></li>
                </ul>
              </li>
            </ul>
          </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
      </nav>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Bootstrap: dropdown

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <div class="dropdown">
        <button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
          Dropdown
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
          <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
          <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
          <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
          <li role="presentation" class="divider"></li>
          <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Separated link</a></li>
        </ul>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Bootstrap: jumbotron

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <div class="jumbotron">
        <h1>Hello, world!</h1>
        <p>Contenuto mooooooolto importante...</p>
        <p><a class="btn btn-primary btn-lg" role="button">Learn more</a></p>
      </div>
    </div>
  </body>
</html>

Bootstrap: full width jumbotron

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="jumbotron">
      <div class="container">
        <h1>Hello, world!</h1>
        <p>Contenuto mooooooolto importante...</p>
        <p><a class="btn btn-primary btn-lg" role="button">Learn more</a></p>
      </div>
    </div>
  </body>
</html>

Bootstrap: page header

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <div class="page-header">
      <h1>Example page header <small>Subtext for header</small></h1>
    </div>
  </body>
</html>

Bootstrap: menu di navigazione

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <ul class="nav nav-pills">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Profile</a></li>
      <li><a href="#">Messages</a></li>
    </ul>
  </body>
</html>

Bootstrap: menu laterale

HTML preview

HTML sourcecode

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Grid System</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="grid.css" rel="stylesheet">
  </head>
  <body>
    <ul class="nav nav-pills nav-stacked">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Profile</a></li>
      <li><a href="#">Messages</a></li>
    </ul>
  </body>
</html>