Showing posts with label CSS Accordion Menu: CSS coding. Show all posts
Showing posts with label CSS Accordion Menu: CSS coding. Show all posts

Monday, 9 December 2013

CSS3 : target-new Property

a
{
target-name:new;
target-new:tab;
}




The target-new property specifies whether new destination links should open in a new window or in a new tab of an existing window





Other Topics

CSS : Relative zoom


Right now, the "zoom in" graphic is linked to an alternate stylesheet with the following css:

body {
zoom: 1.2; -moz-transform: scale(1.2); -moz-transform-origin: 0 0}
} 

This works fine, but ideally I'd like to have the link trigger a relative zoom rather than an absolute zoom value -- so i would need to establish a variable that determined the user's current zoom level, and then increase that zoom by 120%. This way the same link could be clicked multiple times to increase the zoom incrementally.

Other Topics

CSS : Zoom property



The CSS3 equivalent is in the CSS 2D Transforms module, in particular transform: scale().
Because this module is still at Working Draft stage, you'll need browser-specific prefixes:
transform: scale(2);
-moz-transform: scale(2);
-webkit-transform: scale(2);
-o-transform: scale(2);
You may also need transform-origin (and browser-specific versions) to make it behave the same way as zoom, and you'll have to be careful to target zoom only at IE, because WebKit supports bothtransform and zoom so would double-scale.

CSS : Accordion Menu: CSS coding


CSS Accordion Menu: CSS coding








We will create a vertical Accordion Menu in this tutorial and in the next article we will show you how to convert it to a horizontal menu using the same HTML code we used in the last article.
For a simpler version of the CSS Accordion Menu please visit here.
CSS Accordion Menu: The CSS side
First we need to give our accordion a maximum height and a width. We don’t want the text in the <p> tags visible until the accordion has been hovered so we need to set our overflow to hidden. We will also get rid of the bullets from the list, the menu a background color and round off the corners off the menu to make it look a little softer.
So our beginning code should look something like this.
.accordion{
  width:600px;
  overflow:hidden;
  list-style:none;
  margin-bottom:10px;
  background:#ccc;

  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  -o-border-radius:10px;
  border-radius:10px;
}
Next we need to set up the accordion list items CSS for their natural state.
.accordion li {
   height:20%;
   width:100%;
   -moz-transition:height 0.3s ease-out;
   -webkit-transition:height 0.3s ease-out;
   -o-transition:height 0.3s ease-out;
   transition:height 0.3s ease-out;
   overflow: hidden;
}

In this example we have 5 items in our menu so we divided it up into 5 equal parts, thus the 20% for our height. We want our sections to come right across so naturally we set that to 100%. Overflow was set to hidden as we do not want the text appear till we hover over it. The transition lines relate to the smooth sliding effect we are giving our accordion. This property was introduced with CCS3. In this case we have set the height to ease out over .3 of a second when when ever it is increasing or decreasing in height.
So that we retain the nice rounded of shape to our menu we will apply the following code to the first and last list items using the first-of-type and last-of-type psuedo-classes.
.accordion li:first-of-type{
   -moz-border-radius:10px 10px 0 0;
   -webkit-border-radius:10px 10px 0 0;
   -o-border-radius:10px 10px 0 0;
   border-radius:10px 10px 0 0;
}
.accordion li:last-of-type{
   -moz-border-radius:0 0 10px 10px;
   -webkit-border-radius:0 0 10px 10px;
   -o-border-radius:0 0 10px 10px;
   border-radius:0 0 10px 10px;
}

By rounding off the top of the first item and the bottom of our last item we maintain the shape we wanted.

.accordion:hover li{
  height:10%;
  width:100%;
}
.accordion li:hover{
  height:60%;
  width:100%;
}

And our CSS for a vertical accordion menu is complete. Well the basic structure is. In some cases you may have to fiddle with the figures for the sizes to get it right for you depending on your typography etc but that is the back structure.

Other Topics

CSS : Drop down menu


he first part of this tutorial is dedicated to the task of building a working CSS-only dropdown menu (also known as suckerfish menu), the second part will show you how you can pimp the whole thing with a few lines of jQuery.
The CSS-only menu is cross browser tested and from what I can tell works with all browsers except for IE6.
The Internet Explorer needs the addition of our jQuery function to work properly.
To create a CSS-only dropdown menu that works without Javascript (even in IE6), you need tons of extra markup and CSS, if you really need this for any reason check out Stu Nicholls CSSplay, he addresses this problem with heavy (ab)use of conditional comments =)
Now that you have a little bit of background information, lets create our own menu:
First of all we need the XHTML Structure of our soon-to-be terrific menu. We will use a nested list for this purpose, top level list id is “nav”:
<ul id="nav">
    <li><a href="#">1 HTML</a></li>
    <li><a href="#">2 CSS</a></li>
    <li><a href="#">3 Javascript</a>
        <ul>
            <li><a href="#">3.1 jQuery</a>
                <ul>
                    <li><a href="#">3.1.1 Download</a></li>
                    <li><a href="#">3.1.2 Tutorial</a></li>
                </ul>
            </li>
            <li><a href="#">3.2 Mootools</a></li>
            <li><a href="#">3.3 Prototype</a></li>
        </ul>
    </li>
</ul>
Thats it for the HTML part; without CSS styling our menu looks like this: Step 1
Now for the stylesheet part:
#nav, #nav ul{
     margin:0;
     padding:0;
     list-style-type:none;
     list-style-position:outside;
     position:relative;
     line-height:1.5em;
 }
This removes the indents browsers tend to make, as well as the bullets from #nav and all its child-ul elements. The “position:relative” is needed since we will arrange some of the contained elements with position:relative and absolute. This is necessary since relative and absolute positioned elements are positioned according to their containing blocks with a position attribute, other then static.
Line-height defines the height of each list item. You could set the height attribute for your list-items to define their height, but line-height will center the link text vertically without the need to play with margins and paddings.
 #nav a:link, #nav a:active, #nav a:visited{
    display:block;
    padding:0px 5px;
    border:1px solid #333;
    color:#fff;
    text-decoration:none;
    background-color:#333;
 }

#nav a:hover{
    background-color:#fff;
    color:#333;
}
This one is pretty straight forward:
it will style each hyper link in our menu a little bit. At this time the menu looks like this:Step 2
Now lets add some more styles:
#nav li{
    float:left;
    position:relative;
}
This will align our list elements horizontally.
#nav ul {
    position:absolute;
    width:12em;
    top:1.5em;
    display:none;
}
This will position the nested Lists right beyond the main menu and give them a width of 12em. The width attribute is needed so that the list items within display vertically again. The Top attribute should have the same value as the line-height attribute we defined for #nav.
#nav li ul a{
    width:12em;
    float:left;
}
This will set the width of the hyper links to 12 em (which in combination with the width of the UL set above results in a horizontally displayed sub menu, despite of the ongoing float:left)
#nav ul ul{
 top:auto;
 }

#nav li ul ul {
    left:12em;
    margin:0px 0 0 10px;
    }

#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul{
    display:none;
    }
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul{
    display:block;
    }
#nav ul ul and #nav li ul ul define where we display the sub menus.
The hover states define which items we want to show when hovering over an item (only the next sub level, not all of them)
After applying these styles we got this menu: Step3
If you are working with a browser other than IE6 you should have a basic dropdown menu now.

Gogo jQuery!

So lets spice up the menu a little bit. First of all here is the whole jQuery Code I used to create the effect:
function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
  $(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
  },function(){
  $(this).find('ul:first').css({visibility: "hidden"});
  });
}

 $(document).ready(function(){
 mainmenu();
});
Step by step description:
$(" #nav ul ").css({display: "none"}); // Opera Fix
This is a small fix for Opera, which doesn’t hide the menus fast enough, if you hover above them and so creates a flickering effect. $(” #nav ul “) is the jQuery way to select all unordered lists in #nav. Usage of this is similar to selecting CSS elements. The.css({display:”none”}) sets the display attribute for all Unordered lists to none.
$(" #nav li").hover(function(){ // here goes mouse over effect
                  },function(){ // here goes mouse out effect
                               });
This is the jQuery function for hovering. Really simple to use: first function lets you define what happens when you hover over a specific item( in our case a list item), second function is used for the mouse out event.
$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).show(400);
This function finds the first hidden unordered list within the currently hovered list item and shows it. The function “.show” works only under specific circumstances, this is why we set the display to none. The number between the braces defines the animation speed in milliseconds.
$(this).find('ul:first').css({visibility: "hidden"});
This is the mouse out event: we use visibility instead of display since the show function mentioned above, sets display to “block” at the end of the animation. This way if you would hover just a short moment over the item the item would not display for the ongoing animation and then pop out all of a sudden. Using visibility prevents this flickering.
 $(document).ready(function(){
 mainmenu();
});
This function will call our mainmenu() function as soon as the html document is ready.

Other Topics

Physics basic inventions and inventors

1.Which instrument is used to measure altitudes in aircraft's ? Audiometer Ammeter Altimeter Anemometer Explanation : ...