Create An Animated CSS Box Menu

In this tutorial were going to play with CSS transitions to create a new style navigation menu. The effect we are aiming for is having a number of navigation boxes, and when the mouse hovers over a box this will grow and shrink the other boxes. We can even add an icon to animate into the box to represent the page on the navigation.

View the demo to see this effect.

Demo

CSS Flexible Box Menu

CSS Flexible Box Menu About

CSS Flexible Box Menu Services

The HTML

First were going to start off with the HTML for the navigation boxes. This consists of a wrapper div element with the boxes inside. Each of the boxes will have text for the page and an image icon to represent the page.

<div class="nav">
<div class="box home">
	<a href="#home">HOME
	<span><img src="./images/home.png" alt="" /></span></a>
     </div>
<div class="box about">
	<a href="#about">ABOUT
	<span><img src="./images/person.png" alt="" /></span></a>
      </div>
<div class="box portfolio">
	<a href="#portfolio">PORTFOLIO
	<span><img src="./images/folder.png" alt="" /></span></a>
      </div>
<div class="box services">
	<a href="#services">SERVICES
	<span><img src="./images/screw-driver.png" alt="" /></span></a>
     </div>
<div class="box contact">
	<a href="#contact">CONTACT
	<span><img src="./images/mail-back.png" alt="" /></span></a>
     </div>
</div>

Styling The Boxes

The CSS will provide all the functionality for the navigation bar. We start off by styling each of the individual boxes, we set the height and width of the boxes to what ever we want to fill the screen. Add a display: inline-block so that the box will display next to each other instead of on top of each other.

As we are going to animate in an icon we want to make sure that we hide anything that overflows this element by using the overflow:hidden property.

Then we can add the transition for the width of the box so that on the hover event we can change the width of the boxes.

.box
{
	display: inline-block;
        float:left;
	height:200px;
	overflow: hidden;
	width:20%;
	-webkit-transition: width 1s;
	-moz-transition: width 1s;
        transition: width 1s;
}

Now we can style the background colours of the different boxes.

.box.home      { background-color: #2d89ef; }
.box.about     { background-color: #00a300; }
.box.portfolio { background-color: #e3a21a; }
.box.services  { background-color: #9f00a7; }
.box.contact   { background-color: #ee1111; }

As we want the entire box area to be clickable we have to change the anchor link into a block element by using the display: block property and making the height of the link 100% of the box. This will make the entire box area a clickable link.

.box a
{
	color:#FFF;
	text-decoration: none;
	text-align: center;
	vertical-align: middle;
	height:100%;
	display:block;
        padding-top: 20px;
}

We want to make an icon animate into the box when you hover over the box, this will use CSS transitions to change the top property of a span tag, inside the tag will be an image we can use for the icon. At the start we need to move this image outside of the element, which will make it hidden by using the overflow: hidden property on the box element. Then we can use the position: relative property with top of 100% to move the span outside of the element.

Adding a transition on to the top property will animate the icon into the box when you hover over.

.box span
{
    display:block;
    position:relative;
    top:100%;
    text-align: center;
    -webkit-transition: top 1s;
    -moz-transition: top 1s;
    transition: top 1s;
}

The Hover Event

Creating the hover event for the navigation, when a user moves the mouse over the box 3 things will happen.

  • First all the boxes are going to shrink to 10% width.
  • The box that we are hovering over will be expanded to be 60% width.
  • Then the box we are hovering over has a span tag inside, this will then change the top property back to 25% bringing the element back into view.
.nav:hover .box { width:10%; }
.nav .box:hover { width: 60%; }
.box:hover span{ top:25%; }

Demo

Resize Image Class With PHP

A common feature that you will across in websites is the ability to resize an image to fit an exact size so that it will displayed correctly on your design. If you have a very large image and you are going to place it on your website in a space that is only 100px x 100px then you will want to be able to resize this image to fit in the space.

One option is to just set the width and height attributes on the image tag in your HTML, this will force the image to be displayed at this size.

<img src="image.png" height="100" width="100" alt="Example of resizing an image" />

This will work perfectly fine and the image will fit in the 100px x 100px space but the problem is that when the browser loads the image it will not resize the image but will just display it in the limited size. This means that the image will still need to be downloaded at full size, if the image is very large it can take some time for you to download a large image just to be displayed in a small space.
Continue reading »

CSS Flip Boards

In this tutorial we are going to create a flip board effect by using CSS, there are 2 effects we can create one the hover event we are going to have one board flip on the horizontal and another board which will flip on the vertical.

This effect can be used to hide content from the user until they hover over the board this will then display the hidden board.

front board

flipped board

View the demo to see the effect.

Demo
Continue reading »

Add Twitter Cards To Your Website

When you share a post on a social network like Facebook it will scan the URL that you are sharing and return certain information to display the page in your feed. Facebook will get the page title, page description and a thumbnail image for the page. You can change the information that Facebook gets by using the open graph meta tags.

These are simply meta tags you can add to the head tag of your page, when Facebook scans your page to get the title, description and images it will search for these tags, if they are there then it will use the contents of these tags instead of the page title. These means you can fully customise the page titles just for Facebook.

card-web-summary_0

Twitter also has meta tags which you can use to customise the message on Twitter. These are called Twitter cards, it allows website owners to add more descriptive text on their links when they are shared on Twitter.
Continue reading »

Validate Featured Image On Post

Since WordPress version 2.9 you have been able to add a post thumbnail to all your posts on your website. A post thumbnail is called a featured image for the posts, this image can be displayed in anyway you want, it is up to the theme developer. The benefit of this image is that it allows you to add an image to a post without it appearing in the content of the actual post.

This will allow you to use an image to display the post instead of just the content. The main use of this image is to be used on the index page or the search results page of your WordPress site.

Enable Theme Support For Featured Post

By default themes do not support this feature you need to add some code to the functiona.php file.

add_theme_support( 'post-thumbnails' );

Continue reading »

Always Get A Checkbox $_POST Value

The problem with checkboxes is that if they are not checked then they are not posted with your form. If you check a checkbox and post a form you will get the value of the checkbox in the $_POST variable which you can use to process a form, if it's unchecked no value will be added to the $_POST variable.

In PHP you would normally get around this problem by doing an isset() check on your checkbox element. If the element you are expecting isn't set in the $_POST variable then we know that the checkbox is not checked and the value can be false.

if(!isset($_POST['checkbox1']))
{
     $checkboxValue = false;
} else {
     $checkboxValue = $_POST['checkbox1'];
}

But if you have created a dynamic form then you won't always know the name attribute of your checkboxes, if you don't know the name of the checkbox then you can't use the isset function to check if this has been sent with the $_POST variable.

To get around this problem you can use a new hidden element which will store the true value of the checkbox. What you need to do is create a hidden element and use Javascript to change the value of the hidden field to the true value of the checkbox.
Continue reading »

Display A List Of Authors On WordPress

On some blogs it is important to post on a regular basis, but this can be difficult unless blogging is your full time job.

For a single person to regularly post awesome blog posts everyday can take up a lot of time. For this reason many blogs have a number of authors, this helps keep the content regular and high quality to ensure a better blog.

On a single author blog you will normally find an about page that will tell you information about the author. You can do this on a multi author blog but you also need to create a page that will display all the authors on the blog so you can link to each of their posts.

If you want to create a page to display all the authors you have two options, you can create a new page template which will allow you to code the layout of the page to show all the authors. The other option is to create a shortcode where the user of the site can use this on a new page content to create a list of all the authors.

The two options should be decided on if you are going to add this functionality in a plugin or a theme. If you are going to add this functionality to the theme then you should use a page template, if you want to use the shortcode then you should do this with a plugin. In this tutorial we are going to create a page template to display all the authors on the site.

Create A Page Template

First start off by creating a new page template for your list of all authors.

/*
Template Name: Display All Authors
*/

Continue reading »

Add Google+ Comments To Your Site

On the 18th April 2013 Google announced that they have made a Google Plus commenting system which you can have on your website just like the Facebook comments. This allows people to come to your site and when they comment on an article this comment will be shared on Google plus.

Google+ Comments

The difference that Google plus comments has over Facebook comments is a massive benefit of including all comments from Google plus on your page. This means that if someone shares your article on Google plus it will appear in your commenting system, if this then leads to a conversation happening on Google Plus about your article this will also appear on your comment system. So all conversations that are happening about your page will come through and be displayed on your website. This allows you to keep in touch with every conversation that is happening on Google plus about your page.
Continue reading »

Recreate The Github Search Box

In this tutorial we are going to recreate a slide out search box just like what you will find on Github.

GitHub

What's different about this search box is that it will start with a small width and then when the user clicks into it to write their search it uses CSS transition to change the width of the search box.

The whole process of this is quite simple using basic CSS transitions but I think the effect is done really well.
Continue reading »

Creating A Custom Taxonomy In WordPress

WordPress comes with inbuilt functionality which enables you to group posts or post types together. This functionality is called a taxonomy, by default WordPress comes with two default types, there is categories and tags. The difference between a category and a tag is that categories can be grouped in a hierarchy so you can have parent categories.

Tags give you more freedom then categories you can add new tags easily by typing them in the tags textbox on the post screen. Normally a post will have multiple tags but will only one category.

In a normal blog website having just categories and tags is enough functionality to group your posts, but WordPress is a CMS and can be used to create custom post types. These new post types might not fit into the previous taxonomies you have used, so you might have to create a new taxonomy to allow you to group your new post types.
Continue reading »