Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap Layout

Bootstrap Layout

Introduction

In this tutorial, you will learn how to use the Bootstrap toolkit to create fixed and fluid layouts. The tutorial is based on Bootstrap version 2.0.

In version 2.0, Bootstrap added responsive features for phones, tablets, laptops, small desktops, large widescreen desktops, and more.
You can make the layout responsive by adding the bootstrap-responsive.css file (located under docs/assets/css) to the page.

Bootstrap Fixed Layout

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

Usage





  
...

Explanation

Lines 261 to 273 of bootstrap.css (located under docs/assets/css in the bootstrap main folder) render styles for creating the main container, thereby creating a fixed layout. The purpose of a fixed layout is to create a 940-pixel (default) wide layout for a web page or app.

Example of a Bootstrap Fixed Layout

The following code creates a fixed layout for a web page. For customization, in addition to the default styles, you need to create a new CSS file, example-fixed-layout.css, located in the same folder as bootstrap.css.

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

Example

    

     An example using a Bootstrap version 2.0 fixed layout

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

        

        

            

w3cschool Web Store

            

Try and purchase HTML5, JS, Ruby, PHP-MySQL based web apps to enhance your productivity at affordable price.

            

                Sign Up for a 30 day free trial

        

        

        

            

                

HTML5 and JS Apps

                

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.

                

                    View apps

            

            

                

Ruby Apps

                

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.

                

                    View apps

            

            

                

PHP MySQL Apps

                

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.

                

                    View apps

            

        

        


        

            

© Company 2012

        

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

Output

bootstrap fixed layout example

View online

View the example above in different browser windows.

Bootstrap Fluid Layout

If you want to create a non-fixed layout, i.e., a percentage-based layout, to make the layout more flexible, see this part of the tutorial.

Usage



Explanation

Lines 274 to 285 of bootstrap.css (located under docs/assets/css in the bootstrap main folder) render styles for creating the main container, thereby creating a fluid layout. The purpose of a fluid layout is to create a percentage-based layout (for example, width=20%) for a web page or app.

Example of a Bootstrap Fluid Layout

The following code creates a fluid layout for a web page. For customization, in addition to the default styles, you need to create a new CSS file, example-fluid-layout.css, located in the same folder as bootstrap.css.

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

Example

    

     An example using a Bootstrap version 2.0 fixed layout

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

        

            

                

            

            

                

                    

Learn. Practice. Develop.

                    

w3cschool offers web development tutorials. We believe in Open Source. Love standards. And prioritize simplicity and readability while serving content.

                    

                        Join w3cschool now

                

                

                    

                        

Learn

                        

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.

                        

                            Start Learning now

                    

                    

                        

Practice

                        

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.

                        

                            Start percticing now

                    

                    

                    

                        

Develop

                        

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.

                        

                            Start developing now

                    

                

                


                

                    

© Company 2012

                

            

        

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

    

Output

bootstrap fluid layout example

View online

View the example above in different browser windows.

Click here to download all the HTML, CSS, JS, and image files used in this tutorial.