Latest web development tutorials

Bootstrap layout

Brief introduction

In this tutorial, you will learn how to use the Bootstrap toolkit to create a fixed layout and flow layout. Bootstrap tutorial is based on version 2.0.

In version 2.0, Bootstrap for mobile phones, tablets, laptops, small desktop machine, large widescreen desktop, etc. Add a response.
You can add a file to bootstrap-responsive.css page (located docs \ assets \ css under) to make the layout responsive.

Bootstrap fixed layout

If you want to create a web page based on a fixed number of pixels or app, see this part of the tutorial.

usage

<Body>
  <Div class = "container">
    ...
  </ Div>
</ Body>
            

Explanation

bootstrap.css (docs located bootstrap main folder \ assets \ css under) first 261-273 line, to create the main container rendering styles to create a fixed layout. The purpose is to create a fixed layout 940 pixels for web or app (default) width layout.

Examples of Bootstrap fixed layout

The following code creates a fixed page layout. For customization, in addition to the default style, the need to create a new css file example-fixed-layout.css, and bootstrap.css located in the same folder.

CSS code

body {
padding-top: 60px;
padding-bottom: 40px;
}
.nav li {
padding-top: 5px;
}
.leaderboard {
padding: 60px;
margin-bottom: 30px;
background-image: url ( '../ twitter-bootstrap / images / gridbg.gif');
background-repeat: repeat;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
.leaderboard h1 {
font-size: 40px;
margin-bottom: 5px;
line-height: 1;
letter-spacing: -1px;
color: # FF6600;
}
.leaderboard p {
font-size: 18px;
font-weight: 200;
line-height: 27px;
}

HTML code

Examples

<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "utf-8">
<Title> using Bootstrap Version 2.0 fixed layout examples </ title>
<Meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<Meta name = "description" content = "Example of Fixed Layout with Bootstrap version 2.0 from w3cschool.cc">
<Meta name = "author" content = "">
<-! Le styles ->
<Link href = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / css / bootstrap.css" rel = "stylesheet">
<Link href = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / css / example-fixed-layout.css" rel = "stylesheet">
<-! Le HTML5 shim, for IE6-8 support of HTML5 elements ->
<-! [If lt IE 9]>
<Script src = "// html5shim.googlecode.com/svn/trunk/html5.js"> </ script>
<! [Endif] ->
<-! Le fav and touch icons ->
<Link rel = "shortcut icon" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / favicon.ico">
<Link rel = "apple-touch-icon" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon.png">
<Link rel = "apple-touch-icon" sizes = "72x72" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon-72x72.png">
<Link rel = "apple-touch-icon" sizes = "114x114" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon-114x114.png">
</ Head>

<Body>
<Div class = "navbar navbar-fixed-top">
<Div class = "navbar-inner">
<Div class = "container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<Span class = "icon-bar"> </ span>
<Span class = "icon-bar"> </ span>
<Span class = "icon-bar"> </ span>
</a>
<a class="brand" href="#">
<Img src = "/ images / w3r.png" width = "111" height = "30" alt = "w3cschool logo" /> </a>
<Div class = "nav-collapse">
<Ul class = "nav">
<Li class = "active">
<a href="#"> Home </a> </ li>
<Li>
<a href="#about"> About </a> </ li>
<Li>
<a href="#contact"> Contact </a> </ li>
</ Ul>
</ Div>
<-! / Nav-collapse -.> </ Div>
</ Div>
</ Div>
<Div class = "container">
<-! Main hero unit for a primary marketing message or call to action ->
<Div class = "leaderboard">
<H1> w3cschool Web Store </ h1>
<P> Try and purchase HTML5, JS, Ruby, PHP-MySQL based web apps to enhance your productivity at affordable price. </ P>
<P>
<a class="btn btn-success btn-large"> Sign Up for a 30 day free trial </a> </ p>
</ Div>
<-! Example row of columns ->
<Div class = "row">
<Div class = "span4">
<H2> HTML5 and JS Apps </ h2>
<P> Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> View apps </a> </ p>
</ Div>
<Div class = "span4">
<H2> Ruby Apps </ h2>
<P> Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> View apps </a> </ p>
</ Div>
<Div class = "span4">
<H2> PHP MySQL Apps </ h2>
<P> Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> View apps </a> </ p>
</ Div>
</ Div>
<Hr>
<Footer>
<P> & copy; Company 2012 </ p>
</ Footer>
</ Div>
<-! / Container ->
<-! Le javascript ============================================ ====== - ->
<-! Placed at the end of the document so the pages load faster ->
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / jquery.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-transition.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-alert.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-modal.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-dropdown.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-scrollspy.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-tab.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-tooltip.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-popover.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-button.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-collapse.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-carousel.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-typeahead.js"> </ script>
</ Body>
</ Html>

Export

bootstrap fixed layout example

View Online

See examples above in a different browser window.

Bootstrap Fluid Layout

If you want to create a non-fixed layout that is based on a percentage of the layout, in order to allow a more flexible layout, see this tutorial.

usage

<Div class = "container-fluid">
  <Div class = "row-fluid">
    <Div class = "span2">
      <-! Sidebar content ->
    </ Div>
    <Div class = "span10">
      <-! Body content ->
    </ Div>
  </ Div>
</ Div>

Explanation

bootstrap.css (docs located bootstrap main folder \ assets \ css under) first 274-285 line, to create the main container rendering styles to create a flow layout. The purpose is to create a flow layout based on a percentage of the layout (eg, width = 20%) as a Web page or app.

Examples of Bootstrap Fluid Layout

The following code creates a page layout flow. For customization, in addition to the default style, the need to create a new css file example-fluid-layout.css, and bootstrap.css located in the same folder.

CSS code

 body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
	  .nav li {
	  padding-top: 5px;
	  }
	  
	  .sidebar-nav {
        padding: 9px 0;
      }
	  .leaderboard {
  padding: 60px;
  margin-bottom: 30px;
  background-image: url ( '../ twitter-bootstrap / images / gridbg.gif');
  background-repeat: repeat;
  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
  border-radius: 6px;
}
.leaderboard h1 {
  font-size: 40px;
  margin-bottom: 5px;
  line-height: 1;
  letter-spacing: -1px;
  color: # FF6600;
}
.leaderboard p {
  font-size: 18px;
  font-weight: 200;
  line-height: 27px;
}

.well {
background-image: url ( '../ twitter-bootstrap / images / gridbg.gif');
  background-repeat: repeat;
  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
  border-radius: 6px;
}

.nav .nav-header {
font-size: 18px;
color: # FF9900;
}

HTML code

Examples

<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "utf-8">
<Title> using Bootstrap Version 2.0 fixed layout examples </ title>
<Meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<Meta name = "description" content = "Example of Fluid Layout with Bootstrap version 2.0 from w3cschool.cc">
<Meta name = "author" content = "">
<-! Le styles ->
<Link href = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / css / bootstrap.css" rel = "stylesheet">
<Link href = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / css / example-fluid-layout.css" rel = "stylesheet">
<-! Le HTML5 shim, for IE6-8 support of HTML5 elements ->
<-! [If lt IE 9]>
<Script src = "// html5shim.googlecode.com/svn/trunk/html5.js"> </ script>
<! [Endif] ->
<-! Le fav and touch icons ->
<Link rel = "shortcut icon" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / favicon.ico">
<Link rel = "apple-touch-icon" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon.png">
<Link rel = "apple-touch-icon" sizes = "72x72" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon-72x72.png">
<Link rel = "apple-touch-icon" sizes = "114x114" href = "../ bootstrap / twitter-bootstrap-v2 / docs / examples / images / apple-touch-icon-114x114.png"> </ head >

<Body>
<Div class = "navbar navbar-fixed-top">
<Div class = "navbar-inner">
<Div class = "container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<Span class = "icon-bar"> </ span>
<Span class = "icon-bar"> </ span>
<Span class = "icon-bar"> </ span>
</a>
<a class="brand" href="#">
<Img src = "/ images / w3r.png" width = "111" height = "30" alt = "w3cschool logo" /> </a>
<Div class = "nav-collapse">
<Ul class = "nav">
<Li class = "active">
<a href="#"> Home </a> </ li>
<Li>
<a href="#about"> About </a> </ li>
<Li>
<a href="#contact"> Contact </a> </ li>
</ Ul>
<P class = "navbar-text pull-right"> Logged in as
<a href="#"> username </a> </ p>
</ Div>
<-! / Nav-collapse -.> </ Div>
</ Div>
</ Div>
<Div class = "container-fluid">
<Div class = "row-fluid">
<Div class = "span3">
<Div class = "well sidebar-nav">
<Ul class = "nav nav-list">
<Li class = "nav-header"> Frontend </ li>
<Li class = "active">
<a href="#"> HTML 4.01 </a> </ li>
<Li>
<a href="#"> HTML5 </a> </ li>
<Li>
<a href="#"> CSS </a> </ li>
<Li>
<a href="#"> JavaScript </a> </ li>
<Li>
<a href="#"> Twitter Bootstrap </a> </ li>
<Li>
<a href="#"> Firebug </a> </ li>
<Li class = "nav-header"> Backend </ li>
<Li>
<a href="#"> PHP </a> </ li>
<Li>
<a href="#"> SQL </a> </ li>
<Li>
<a href="#"> MySQL </a> </ li>
<Li>
<a href="#"> PostgreSQL </a> </ li>
<Li>
<a href="#"> MongoDB </a> </ li>
</ Ul>
</ Div> <-!. / Well ->
</ Div> <-! / Span ->
<Div class = "span9">
<Div class = "leaderboard">
<H1> Learn. Practice. Develop. </ H1>
<P> w3cschool offers web development tutorials. We believe in Open Source. Love standards. And prioritize simplicity and readability while serving content. </ P>
<P>
<a class="btn btn-success btn-large"> Join w3cschool now </a> </ p>
</ Div>
<Div class = "row-fluid">
<Div class = "span4">
<H2> Learn </ h2>
<P> Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> Start Learning now </a> </ p>
</ Div> <-! / Span ->
<Div class = "span4">
<H2> Practice </ h2>
<P> Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> Start percticing now </a> </ p>
</ Div>
<-! / Span ->
<Div class = "span4">
<H2> Develop </ h2>
<P> Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </ p>
<P>
<a class="btn btn-success btn-large" href="#"> Start developing now </a> </ p>
</ Div> <-! / Span ->
</ Div> <-! / Row ->
<Hr>
<Footer>
<P> & copy; Company 2012 </ p>
</ Footer>
</ Div>
</ Div>
</ Div> <-!. / Fluid-container ->

<-! Le javascript ============================================ ====== - ->
<-! Placed at the end of the document so the pages load faster ->
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / jquery.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-transition.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-alert.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-modal.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-dropdown.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-scrollspy.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-tab.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-tooltip.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-popover.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-button.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-collapse.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-carousel.js"> </ script>
<Script src = "../ bootstrap / twitter-bootstrap-v2 / docs / assets / js / bootstrap-typeahead.js"> </ script>
</ Body>
</ Html>

Export

bootstrap fluid layout example

View Online

See examples above in a different browser window.

Click here to download the tutorial to use all the HTML, CSS, JS and image files.