Thursday 4 December 2014

Editable div in Html 5 with contenteditable attribute

We use input or textarea are use to edit or input text. But now a days when we need design as well as editable things we need more than that.

The contenteditable attribute specifies whether the content of an element is editable or not.

Any elements with the 
contenteditable attribute set will have a grey outline as you hover over. Feel free to edit and change their contents. I'm using local storage to maintain your changes.

           contenteditable=""  or  contenteditable="true"
Indicates that the element is editable.

           contenteditable"false"
Indicates that the element is not editable.

            contenteditable"inherit"
Indicates that the element is editable if its immediate parent element is editable. This is the default value.


 This is div with 'contenteditable' true.
<div id="example" contenteditable="true">

Editable text



Simple popup box in Jquery

While building dynamic web pages popups are useful for showing information of inputs other than content that is shown on page. Mostly html alert popup is used to some info like 'alerts or information for website'. But when development needs popup that do multiple things with multiple formats, alert box is not enough.

Jquery popup


          In this case we need a custom pop up that satisfy our need. We can see that there are many jquery plugin that provide custom popup. But they come with external js & css files with complex format to implement. That is why I want to built my own custom popup.

          We will build this with ‘div’ in html, which will be hidden on page load.  After clicking on link this popup will be shown by jquery. The code is given below

<!DOCTYPE html>
<html lang="en">
<head>
    <title>test</title>

<style>
.popup-back {
    float: left;
    background-color: rgba(51, 51, 51, 0.71);
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    display:none;
    z-index:10000;
}

.popup-con {
    margin: auto;
    width: 600px;
    position: relative;
}

.popup-body {
    background-color: #fff;
    padding: 10px;
    position: absolute;
    width: 100%;
    top: 100px;
}

a.close-popup {
font-family: arial;
text-decoration: none;
background-color: #333;
color: #fff;
border-radius: 50%;
height: 21px;
position: absolute;
width: 20px;
text-align: center;
right: 5px;
top: 5px;

}
    </style>
   
</head>
<body>

<h1>Pop ups</h1>
<a href="#" class="link-class popup-link" rel="my_popup1">popup 1</a>
<a href="#" class="link-class popup-link" rel="my_popup2">popup 2</a>

<div class="popup-back popup-spclass" id="my_popup1">

        <div class="popup-con">
                <div class="popup-body">

                <a href="#" class="close-popup"></a>
                        <h1>this is my 1st popup</h1>

                        <p>Simple way for popup</p>
               
                </div>
        </div>


</div>


<div class="popup-back popup-spclass" id="my_popup2">

        <div class="popup-con">
                <div class="popup-body">

                <a href="#" class="close-popup"></a>
                        <h1>this is my 2nd popup</h1>

                        <p>Simple way for popup</p>
               
                </div>
        </div>


</div>


 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(".popup-link").click(function () {
            var popupId = "#" + $(this).attr("rel");

            $(popupId).fadeIn();


        });
        $(".close-popup").click(function () {

            $(".popup-spclass").fadeOut();


        });
       
    </script>
</body>
</html>




Wednesday 8 October 2014

10 Responsive Html5 - Css3 website templates free

SquadFree – Bootstrap Free HTML Template



Sublime – Stunning HTML5/CSS3 Website Template


Timber – Free One Page Bootstrap Template


E-Shopper – Best Free Ecommerce HTML Template


AdminLTE Dasboard and Control Panel Template


Magnetic – Free Photography Website Template


Mabur Portfolio Theme


Modern Bootstrap HTML Template


Sport Business Html Template


Crafty – Corporate HTML Template




Monday 29 September 2014

Simple Jquery Accordion div for your website

Accordion is expandable and collapsible content holder that is broken into sections and probably looks like tabs. On net you will get plenty of Accordion plug-ins which are with their complicated structure and heavy js files. So they are hard to modify   as per your requirement.



I am writing here a simple and light weight jquery accordion. This is basic structure with scope of modifications. So try this out.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Accordion</title>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".accordiondiv h1").click(function () {
                $('.active').removeClass('active');
                $(this).addClass('active');

                $(this).siblings('.accordionbody').slideToggle();


            });

        });
    </script>
    <style>
        .accordionbody
        {
            display: none;
            border: 1px solid;
            padding: 8px;
        }
        .accordiondiv h1
        {
            background-color: #333;
            color: #fff;
            font-weight: normal;
            padding: 10px;
            font-size: 17px;
            margin: 0;
            border: 1px solid;
        }
    </style>
</head>
<body>
    <div class="maindiv">
        <div class="accordiondiv">
            <h1>
                accordion 1</h1>
            <div class="accordionbody">
                some text here
            </div>
        </div>
        <div class="accordiondiv">
            <h1>
                accordion 3</h1>
            <div class="accordionbody">
                some text here
            </div>
        </div>
        <div class="accordiondiv">
            <h1>
                accordion 4</h1>
            <div class="accordionbody">
                some text here
            </div>
        </div>
    </div>
</body>
</html>



Saturday 20 September 2014

Components required for responsive web designing





Responsive web design (RWD) is a web design approach aimed at making websites change itself to provide an optimal viewing experience—easy reading and navigation with a minimum of resizing, panning, and scrolling—across a wide range of devices (from mobile phones to desktop computer monitors).

That means make your website to adjust itself as per viewer's screen resolution or device such as mobile or desktop. In this way you can increasing user experience of your website. In this discussion we are going to take look at components that requires to build responsive website.

1)View port
2)css media queries

View port
View port is very important component for your responsive Website. Without it your website can not show phenomena of responsiveness on mobile devices.

View port actual reads width of device and ask browser to do responsive things. View port lies between head tags of your html code.
<meta name="viewport" content="width=device-width, initial-scale=1.0">


Css3 Media queries

Css3 media queries are introduced to targeting different sizes of devices or view port. Basically this gives you to build css to target specific width's devices. Means you can write style separately for mobile devices, tablets and desktops. In this way website fits to that specific device perfectly. But you should design your website differently for each set of devices.

You can include media queries in three ways to your webpage.
1)In the head tag of html you can import different style sheets for different widths of devices, like this
<link href="styles.css" rel="stylesheet" media="all and (max-width: 1024px)">


2)Or you can import external style sheet inside your existing style sheet
@import url(styles.css) all and (max-width: 1024px) {...}


3)Or you can write rules for different media queries inside your single style sheet
@media all and (max-width: 1024px) {...}

Most experts recommend the 3rd one that means write media queries in side your one single css style sheet. Because importing external style sheets may increase your page request, which may cause slowdown your page to load.

Each media query may include a media type. Common media types include all, screen, print, tv, and braille. The HTML5 specification includes new media types, even including 3d-glasses.Screen is default media type if not specified. Way to write media type is
@media only screen {}

@media only print {}


Style you want to apply for screen media (like desktop, mobile etc) go inside '{}' and same for print media.

For responsive website it is necessary to write different styles for different width of screen. So media query gives you that option. You can write it like this
@media only screen and (min-width : 320px) and (max-width : 480px) {
/* Styles */
}


The style written in this media query will apply for screen with width between 320px to 480px.
We can also write in this manner given below
@media only screen and (min-width : 320px){
/* Styles */
}

This will apply style only for screen with above 320px. Here we are not restricting max screen width.
@media only screen and (max-width : 320px) {
/* Styles */
}

This will apply style for screen with below 320px. That means this will never apply for screen width above 320px

Now like this you can write style for specific conditions you need. You can add as many media queries in style sheet you want.

I hope this will help many beginners in responsive web designing.
I next session I am going to discus recommended breakpoints or screen sizes for media queries.