Paulund

Link Indenting With CSS3 Animation

Animation

In website design there is something that your website must always do this is styling your links so that they stand out from normal text on your page. This will make it easy for the user to find where your links are on the page.

Using CSS you can even add a style to the hover event of the link, like what I do on this site on the hover event I change the text to bold. Changing the style on the link allows the link to stand out even more.

I was looking around some sites and saw links in the sidebar of their site and on the link hover event they would indent it so it stood out from the list. I had a look at how they did this effect and they were using jQuery to make the indent animate, I thought you could easily do that in CSS with the new CSS3 animation, in this tutorial I will explain how you can create CSS indenting using CSS3 animation.

Click on the demo button below to see the effect we will be creating.

Demo

The HTML

The HTML for this is going to be just a simple list with links.

<ul class="indenting_links">
	<li><a href="">Link 1</a></li>
	<li><a href="">Link 2</a></li>
	<li><a href="">Link 3</a></li>
	<li><a href="">Link 4</a></li>
	<li><a href="">Link 5</a></li>
	<li><a href="">Link 6</a></li>
	<li><a href="">Link 7</a></li>
	<li><a href="">Link 8</a></li>
	<li><a href="">Link 9</a></li>
	<li><a href="">Link 10</a></li>
</ul>

The CSS3

Now we have defined the HTML we can add the CSS to do the indenting animation.

We already have a class on the list so we can use this to define the CSS.

We need to add the functionality on the hover event of the link so use the following CSS.

.indenting_links li a:hover {
	padding-left:20px;
  	-webkit-transition: padding-left 500ms ease-out;
    -moz-transition: padding-left 500ms ease-out;
    -o-transition: padding-left 500ms ease-out;
    transition: padding-left 500ms ease-out;
}

This CSS will add a padding left of 20 pixel on the hover event of the link using the transition property we can say to use the padding left property and take 500ms to finish.

This is all we need to achieve the link indenting effect give it a go and let me know how you get on with CSS3 animation.

Demo

Getting To Know SEO

Writen By Paul

Paulund is a website dedicated to writing tutorials and code snippets about Web Development, the main subjects are PHP, Wordpress, jQuery, CSS3 and HTML5.

Website: http://www.paulund.co.uk

Feedback

Anything to add?

  • Anonymous

    Awesome tutorial. I just used this effect on my website but I did text-indent instead of padding. For about a year I’d been doing it with jQuery but then I realized I could do it with CSS too!

    Cheers!

    • http://www.paulund.co.uk Paul

      Yea it’s crazy the amount of things you used to do in jQuery you can now do in CSS. Just had a look at your site you have a other animations you must of had to change when CSS animation came in.

      I didn’t think of using text-indent thanks.

      • Anonymous

        Definitely. I’m working on a post right now about how new CSS specs are kind of stepping on JavaScript’s toes a bit. Not that their competitors or that it’s a bad thing but it does interest me how many JS things you can do with CSS now.

        Thanks for stopping by my site! It’s nice to make a connection.

        • http://www.paulund.co.uk Paul

          Very true.

          Have you looked into some of new HTML5 features? There are a many things you can do in HTML5 which you used to do in Javascript, such as form validation. Looks like soon you will be able to make a nice looking interactive site without any Javascript.

          I wrote a post about HTML form features where you can see the form validation stuff.
          http://www.paulund.co.uk/how-to-use-html5-form-features

  • http://www.paulund.co.uk Paul

    Thanks logo blog, glad its helpful.

    Let me know if you have a problem you would like a tutorial for.

  • http://www.newwebtemplates.net/ New Web Templates

    Great work! this coding really works.. thanks for sharing my friend

    • http://www.paulund.co.uk Paul

      Glad it’s helpful

  • Pingback: CSS3 Buttons With Pseudo Classes | timhecker.it