Tag Archives: css

UNd web Template

After a break of 3 months, where I was very busy with my internship at Accenture as a Business Intelligence consultant, I’ll try to post more frequently on this blog. To start here’s a brand new template I made, pretty clear without any fancy effects. Use it for free!

Below is a preview of the template and links to download it:

Sad grey: css3 template

Here is a brand new blog template.
I tried some features of CSS3 which mean you won’t be able to have the same render with navigators that does not fully support CSS3 yet.

This version of CSS really ease the development of webdesign:

  • Include custom fonts
  • Rounded corners
  • Text’s shadows
  • Multiple backgrounds images
  • And many more…

I am thrilled about all of these and I hope that we will be able to use CSS3 as soon as possible. You can take a look at that blog template I was talking about earlier:

Create your first jQuery plugin

In this article I will show you how to create a simple jQuery plugin menu.
First of all, check this demo so you know where we are heading to: smoothymenu plugin.

As you can see, we will create a plugin to render a menu with fading effect on its items.
The first step to create your plugin is to download the latest jQuery library at jquery.com.

Now you can create a new JavaScript file, this file will contain the main function of our plugin (our plugin will also use a CSS file). To declare a plugin function in jQuery you have to use this syntax:

jQuery.fn.smoothymenu = function() {}

Before we get started with the Javascript let’s take a look at an HTML example file. By doing this we can define the basic structure of our menu:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>SmoothyMenu Jquery plugin</title>
	<link href="css/smoothymenu.css" rel="stylesheet" type="text/css" media="screen"></link>
	<script type="text/javascript" src="lib/jquery/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="lib/jquery/smoothymenu.jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			$('ul#menu').smoothymenu();
		});
	</script>
    </head>
    <body>
        <h1>SmoothyMenu Jquery plugin</h1>
 
	<ul id="menu">
		<li>
			<a href="#">Home</a>
		</li>
		<li>
			<a href="#">Contact</a>
		</li>
		<li>
			<a href="#">About</a>
		</li>
	</ul>
    </body>
</html>

As you can see I apply my plugin on a list with an id. Now we can write our plugin, the first step is to retrieve the element we will work with. In or case the list, to do that you can create a variable:

var menu = $(this);

After that, we want to apply some styles to our menu so we will programmatically add a class to the menu. This class is in our CSS plugin file and will be provide with the JavaScript file (of course the end user will be able to customize the CSS to match his needs).

menu.attr('class', 'smoothymenu');

Here is the trick to create the fade in/out: we add a block to each menu item, if the mouse if out of the item it will be not visible, when the user will hover an item we will fade it in and vice-versa.

/* Append the specific effect block to each menu items. */
menu.find('li').append('<div class="hover-effect"></div>');
 
/* Apply an effect on the hover of an element of the menu. */
menu.find('li').bind('mouseover', function(){
	$(this).find('div.hover-effect').stop().fadeTo('fast', 1);
});
 
/* Apply an effect when the mouse is out of an element of the menu. */
menu.find('li').bind('mouseout', function(){
	$(this).find('div.hover-effect').stop().fadeTo('fast', 0);
})

Ok we are done, of course you can add parameters to your function and do more complexes operations.
I tried to keep it it simple in this example, to sum up here is the whole smoothymenu plugin function:

jQuery.fn.smoothymenu = function()
 {
 	var menu = $(this);
 
	/* Define the class of the menu */
	menu.attr('class', 'smoothymenu');
 
	/* Append the specific effect block to each menu items. */
	menu.find('li').append('<div class="hover-effect"></div>');
 
	/* Apply an effect on the hover of an element of the menu. */
	menu.find('li').bind('mouseover', function(){
		$(this).find('div.hover-effect').stop().fadeTo('fast', 1);
	});
 
	/* Apply an effect when the mouse is out of an element of the menu. */
	menu.find('li').bind('mouseout', function(){
		$(this).find('div.hover-effect').stop().fadeTo('fast', 0);
	})
 };

You can download the sources right here: smoothymenu jquery plugin sources (see the demo).

Simple green: another free template

Here is a brand new CSS template I have created.
It is a very basic template (you will tell me it explains its name, true words) with only one column. I still tried to keep it nice. I hope you will enjoy it and once again feel free to use it.

You can take a look at it below and you will find links to see a live demo / download it at the end of the post.

Form alignment without table

In this post I will give you a quick method to align the inputs of your forms with a couple of CSS lines. A couple years ago HTML tables were used to align elements, any changes about the forms were heavy.

First step the HTML code of your form:

<form action="#" method="post">
	<p>
		<label>Name:</label>
		<input type="text" name="txt_name" />
	</p>
	<p>
		<label>Lastname:</label>
		<input type="text" name="txt_lastname" />
	</p>
	<p>
		<input type="submit" value="Send" />
	</p>
</form>

Without CSS your form should be like this:

Now we will add some CSS. The trick is to make your labels floatting on the left and define a width. To make our labels floatting we also have to display them as blocks.

form p label {
	display:block;
	float:left;
	width:100px;
}

And there you go, it is as simple as that.