Translate

Tuesday, November 25, 2014

Twitter Bootstrap Tutorial – In 20 Minutes

BASIC HTML TEMPLATE

We need to start with a basic HTML template so we can include the required bootstrap files. Below is the start to our twitter bootstrap project, copy this code into a file and name it index.html.


<head>
<title>Twitter Bootstrap Tutorial - A responsive layout tutorial</title>
<style type='text/css'>
body {
background-color: #CCC;
}
</style>
</head>
<body>

</body>
</html>
 
We have added some CSS to make the background of the web page a light grey, this is so we can easily see the different columns within our design, making it easier to understand.

INCLUDE TWITTER BOOTSTRAP

To use twitter bootstrap there is only one file that we are required to include into our template, but there are many varieties available, please refer to the documentation if you wish to explore these options.
For the sake of this twitter bootstrap tutorial, we will include one file bootstrap-combined.min.css via CDN so we don’t even need to download any files. Place the following code on the line after the title tags:

<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
 

TWITTER BOOTSTRAP CONTAINER

The bootstrap .container class is very useful and creates a centered area within the page that our other site content can be put within. The .container class is the equivalent of creating a #frame DIV with a static width and setting its margin: to auto; to center it. The benefit of the twitter bootstrap .container is that as it is responsive and will work out the best width to use for the screens current width.
Within the body tags, create a division element with a class of container. This will act as the pages main wrapper where we will place all our other HTML code.

HEADER & NAVIGATION

Now we have a place to add our additional HTML code, we can add the heading text and then create the sites main navigation bar. Add the following text, or text of your choosing within the .container division element.

<h1>TWITTER BOOTSTRAP TUTORIAL</h1>
 
Nothing new here, just a heading, lets swiftly move on to something more interesting, the twitter bootstrap navigation.
Bootstrap has a .nav class that allows us to create all kinds of navigation elements, place the following code after the h1 tags.
<div class='navbar navbar-inverse'>
      <div class='navbar-inner nav-collapse' style="height: auto;">
        <ul class="nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Page One</a></li>
          <li><a href="#">Page Two</a></li>
        </ul>
      </div>
    </div>
 
 
The .navbar class holds all the styles for the navigation bar, then adding the .navbar-inverse class will apply the super cool black style that is so common with twitter bootstrap. I recommend expanding on these styles and creating something really unique, but for this bootstrap tutorial we will be sticking to the basic bootstrap styles.
Within the .navbar division, we add another division element with the class .nav-collapse and some inline CSS of height: auto;. This is telling bootstrap that when the page is viewed within a browser, that has a window size of less that 979px it will provide a compressed alternative view.
If you save the index.html file and preview it in a browser you will be able to see this response on re-sizing the browser window, as illustrated below:

GREATER THAN 979 PIXELS

 

Additionally, we add a .nav class to the un-ordered list HTML element to apply more style from the bootstrap CSS and also add a .active class to the “Home” list element.

MAIN CONTENT & SIDEBAR

We have the main navigation of the site complete, now we need to add the main content area and a sidebar to hold more links / navigation routes. Add the following code directly after the navbar code:

'content'
class='row-fluid'> <div class='span9 main'> <h2>Main Content Section</h2> </div> <div class='span3 sidebar'> <h2>Sidebar</h2> </div> </div>
 
This is where we need to understand the twitter bootstrap grid system, of course the bootstrap documentation covers it in detail here, but we will now cover the basics to get you started.
The grid system utilizes a 12 column layout, meaning that the page can be divided by 12 equal columns if you so desire. The following image from the bootstrap documentation provides a good visual representation.
Twitter Bootstrap Tutorial, Section 4
In the code that we just pasted under the navbar you can see classes span9 and span3. This will divide the page into 9 columns width on the left and then 3 columns width on the right, making our content area and sidebar. A benefit to using this grid system is that it works out the width of each of these columns relative to the screen size, so you don’t have to worry about writing any extra media queries to get the site working on all screen resolutions.
Experiment with this code by changing the span number and then try re-sizing the browser to see the effect. You will notice that after the .container become 724px wide, the columns will stack vertically.
Quickly throw the following text, or any text into the main content area directly after the h2 tags, just to pad out the site a little.

SIDEBAR NAVIGATION

Twitter bootstrap has a set of navigation elements available for use, you can see them all here.
We are going to use the stacked tabs to create an additional navigation pane. Copy and paste the following code after the sidebar h2 tags.

    class="nav nav-tabs nav-stacked"> <li><a href='#'>Another Link 1</a></li> <li><a href='#'>Another Link 2</a></li> <li><a href='#'>Another Link 3</a></li> </ul>
 

CONCLUSION

This twitter bootstrap tutorial was a very quick blast through some of the features that twitter bootstrap can offer, over time and practice along with reading the official documentation it won’t be long before you are a bootstrap wiz.

 


 

 

 


 

 

Wednesday, June 18, 2014

How to Wrap/break continues text in table using CSS

We can wrap/break the continues text in table row using CSS .
Sometime user can entered long content without space between to word. like some big email ids. which can break our fixed layout web template, To avoid this designing problem, please follow following steps

Step 1

Add following code to your CSS file.
1
2
3
4
5
6
7
8
9
.ClassName{
   white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
   white-space: -pre-wrap; /* Opera 4-6 */
   white-space: -o-pre-wrap; /* Opera 7 */
   white-space: pre-wrap; /* css-3 */
   word-wrap: break-word; /* Internet Explorer 5.5+ */
   word-break: break-all;
   white-space: wrap; /* Internet Explorer 8 and other*/
   }

Step 2

Add this class to respective table cell. please refer demo.
Above css class is added to email-id column for wrap email-id content .
USER NAMEE-MAIL IDPHONE NO.CITY
User 1919822565414Chennai
User 2user2@usermail.com919874565412Bangalore

Quick CSS3 and CSS2 shorthand guide

CSS2 and CSS3 Shorthand Guide

CSS shorthand can really help you reduce and optimize CSS files. Instead of using multi-lines of properties, we can make it one liner. The following is the CSS3 and CSS2 shorthands properties:

1. CSS Margin

01
02
03
04
05
06
07
08
09
10
/* use Margin shorthand*/
h1 {margin:5px  10px  5px  10px;}
/* instead of */
h1 {margin-top:5px;
    margin-right:10px;
    margin-bottom:5px;
    margin-left:10px;
}


2. CSS Padding

1
2
3
4
5
6
7
8
h1 {Padding :5px  10px  5px  10px;}
/* instead of */
h1 {Padding-top:5px;
    Padding-right:10px;
    Padding-bottom:5px;
    Padding-left:10px;
}

3. CSS Border

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
h1 {border:1px solid #CCC;}
/* instead of */
h1 {border-width:1px;
    border-style:solid;
    border-color:#CCC;
}
/*** Use border width shorthand ****/
h1 {border-width:1px 2px 3px 4px;}
  
h1 {border-top-width:1px;
    border-right-width:2px;
    border-bottom-width:3px;
    border-left-width:4px;
}

5. CSS3 border-radius

1
2
3
4
5
6
7
8
9
div {border-radius:1px  2px  3px  4px;}
/* instead of */
div {
     border-top-left-radius: 1px;
     border-top-right-radius: 2px;
     border-bottom-right-radius: 3px;
     border-bottom-left-radius: 4px;
}

6. CSS background

01
02
03
04
05
06
07
08
09
10
div {background:#f00 url(background.gif) no-repeat fixed 0 0;}
/* instead of */
div {
     background-color:#f00;
     background-image:url(background.gif);
     background-repeat:no-repeat;
     background-attachment:fixed;
     background-position:0 0/* left top */
}

7. CSS Font

01
02
03
04
05
06
07
08
09
10
11
12
13
14
h1 {font:italic small-caps bold 12px/160% "Lucida Grande",sans-serif;}
/*or with out some optional values*/
h1 {font:bold 12px/160% "Lucida Grande",sans-serif;}
/* instead of */
h1 {font-style:italic;
    font-variant:small-caps;
    font-weight:bold;
    font-size:12px;
    line-height:160%;
    font-family:"Lucida Grande",sans-serif;
}

8. CSS list-style

1
2
3
4
5
6
7
ul {list-style:square inside url(image.gif);}
/* instead of */
ul {list-style-type:square;
    list-style-position:inside;
    list-style-image:url(image.gif);
}

9. CSS Color

when a colour consists of three pairs of hexadecimal digits, you can omit one digit from each pair:
#000000 becomes #000, #336699 becomes #369.
1
2
3
4
h1 {color:#000}
/* instead of */
h1 {color:#000000;}

10. CSS3 box shadow

01
02
03
04
05
06
07
08
09
10
11
12
-moz-box-shadow:    3px 4px 5px 6px #ccc/* for mozilla*/
-webkit-box-shadow: 3px 4px 5px 6px #ccc; /* for chrome and safari */
box-shadow:         3px 4px 5px 6px #ccc;
/*
1.  3px - The horizontal offset (The X-coordinate)
2.  4px - The vertical offset (The y-coordinate)
3.  5px - The blur radius (optional)
4.  6px - The spread radius (optional)
5.  #CCC - Color
*/

11. CSS3 text-shadow

1
2
3
4
5
6
7
8
text-shadow: 1px 2px 3px #000;
/*
1.  1px - The horizontal offset (The x-coordinate)
2.  2px - The vertical offset (The y-coordinate)
3.  3px - The blur radius (optional)
4.  #000- Color
*/

12. CSS3 transition

CSS3 Transitions allow property changes in CSS values to occur smoothly over a specified duration.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
-webkit-transition: background 0.3s ease;    /* chrome & safari */
  -moz-transition: background 0.3s ease;      /* Mozilla */
  -o-transition: background 0.3s ease;       /* opera */
  transition: background 0.3s ease;
/* insted of */
transition-property: background;
transition-duration: 0.3s;
transition-timing-function: ease;
/*
1.  background  - transition-property: The property to be transitioned (in this case, the background property): The property to be transitioned (in this case, the background property).
2.  0.3s - transition-duration (The y-coordinate)
3.  ease - transition-timing-function(optional)
*/

13. CSS3 Animation shorthand


animation: name duration timing-function delay iteration-count direction;
01
02
03
04
05
06
07
08
09
10
11
12
13
-moz-animation: myfirst 5s linear 2s infinite alternate;    /* Firefox: */
-webkit-animation: myfirst 5s linear 2s infinite alternate;  /* Safari and Chrome: */
-o-animation: myfirst 5s linear 2s infinite alternate;  /* Opera: */
animation: myfirst 5s linear 2s infinite alternate;
/* insted of */
animation-name: myfirst;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: running;

14. Comma separated declarations

1
2
3
h1, h2, h3, h4, h5, h6 {
    font-family:Helvetica, Verdana, sans-serif;
}