Share
, , ,

HTML5 Tutorial-2: Incorporating Flexible Box Model

Welcome to My HTML5 Tutorial-2! 

If you have already studied my HTML5 Tutorial-1 then this tutorial is nothing complex. We will use the codes from the previous tutorial to continue our HTML5 tutorial. In this tutorial I have add a new <div> tag to incorporate flexible box model. This flexible box model will give your website a kind of elastic property. Flexible box model is supported by most the latest featured browsers like Google Chrome and Microsoft Edge. For this flexible box model your website will get some flexibility to get the shape of your current window and it will shrink and enlarge its shape towards your defined direction.
HTML5 Flexible Box Model


tutorial.html
  1.  <!doctype html>
  2. <html lang="en">
  3. <head>
  4.                 <meta charset="utf-8"/>
  5.                 <title>Luin's Website</title>
  6.                 <link rel="stylesheet" href="main.css">
  7. </head>
  8. <body>
  9.                 <div id="big_wrapper">
  10.                                 <header id="top_header">
  11.                                                 <h1>Luin's HTML5 Tutorial</h1>
  12.                                 </header>
  13.                                 <nav id="top_menu">
  14.                                                 <ul>
  15.                                                                 <li>Home</li>
  16.                                                                 <li>About</li>
  17.                                                                 <li>Contact</li>
  18.                                                 </ul>
  19.                                 </nav>
  20.                                 <div id="new_div">
  21.                                 <section id="main_section">
  22.                                                 <article>
  23.                                                                 <header>
  24.                                                                                 <h2>The First Article</h2>
  25.                                                                 </header>
  26.                                                                 This is the very first article of my website. This article is just a demo of articles I am going to post in future.
  27.                                                                 <footer>
  28.                                                                                 Written by-Mohammad Luin | Date-15/12/15
  29.                                                                 </footer>
  30.                                                 </article>
  31.                                                 <article>             
  32.                                                                 <header>
  33.                                                                                 <h2>The Second Article</h2>
  34.                                                                 </header>
  35.                                                                 This is the very second article of my website. This article is just a demo of articles I am going to post in future.
  36.                                                                 <footer>
  37.                                                                                 Written by-Mohammad Luin | Date-15/12/15
  38.                                                                 </footer>
  39.                                                 </article>
  40.                                 </section>
  41.                                 <aside id="recent_post">
  42.                                                 <h2>Recent Posts</h2>
  43.                                                 The First Article <br/>
  44.                                                 The Second Article
  45.                                 </aside>
  46.                                 </div>
  47.                                 <footer id="the_footer">
  48.                                                 Copyright Luin 2015
  49.                                 </footer>
  50.                 </div>
  51. </body>
  52. </html>

Description:
20. Introducing new <div> tag for creating flexible box.
46. Closing the new <div> tag.


main.css
*{
                margin: 0px;
                padding: 0px;
}

h1{
                font: bold 20px Tahoma;
}

h2{
                font: bold 14px Tahoma;
}

header, section, footer, aside, article ,nav, hgroup{
                display: block;
}

body{
                width: 100%;
                display: -webkit-box;             /* You have to alter display type to "-webkit-box" to insert body within the flexible box  */
                -webkit-box-pack: center;     /* Use this property to pack your boxes in the center of the website  */
}

#big_wrapper{
                max-width: 1000px;
                margin: 20px 0px;
                display: -webkit-box;              /*  Display type to insert flexible boxes */
                -webkit-box-orient: vertical;  /* This property indicates where and how the block elements will be placed in times of window enlargement and shrinking  */
                -webkit-box-flex: 1;              /* This property means the box is flexible and if we would use '0' instead of '1' then it would be fixed  */
}

#top_header{
                background: yellow;
                border: solid 3px black;
                padding: 20px;
}

#top_menu{
                border: red;
                background: blue;
                color: white;
}

#top_menu li{
                display: inline-block;
                list-style: none;
                padding: 5px;
                font: bold 14px Tahoma;
}

#new_div{
                display: -webkit-box;                  /* Display type to insert flexible boxes  */
                -webkit-box-orient: horizontal;  /* Elements within this box will be placed horizontally */
}

#main_section{
                border: 1px solid red;
                -webkit-box-flex: 1;           /* This property means the box is flexible and if we would use '0' instead of '1' then it would be fixed  */
                margin:20px;
                padding: 20px;
}

article{
 background: #B6B3B2;  /* Background color of each article */
 border: 1px solid red;     /* Article border size and color */
 padding: 20px;
 margin-bottom: 15px;
}

#recent_post{
                border: 1px solid red;
                width: 220px;
                margin: 20px 0px;
                padding: 20px;
                background: #66CCCC;
}

#the_footer{
                text-align: center;
                padding: 20px;
                border-top: 2px solid green;
}

Result:

0 comments:

Post a Comment