Quick Tip: Practical CSS Shapes
videos

Quick Tip: Practical CSS Shapes

Tutorial Details
  • Topic: CSS
  • Difficulty: Intermediate
  • Estimated Completion Time: 4 Minutes

A common design technique lately is to create a fold effect, where it appears as if a heading is wrapping behind its container. This is generally achieved through the use of tiny images; however, with CSS, we can mimic this effect quite easily. I’ll show you how in four minutes.

Example

Final HTML

<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>CSS Shapes</title>

	<!--[if IE]>
		<style>
			.arrow { top: 100%; }
		</style>
	<![endif]-->

</head>
<body>
	 <div id="container">

		<h1> My Heading <span class="arrow"></span> </h1>

	</div>
</body>
</html>

Final CSS

#container {
	background: #666;
	margin: auto;
	width: 500px;
	height: 700px;
	padding-top: 30px;
	font-family: helvetica, arial, sans-serif;
	}

h1 {
	 background: #e3e3e3;
	 background: -moz-linear-gradient(top, #e3e3e3, #c8c8c8);
	 background: -webkit-gradient(linear, left top, left bottom, from(#e3e3e3), to(#c8c8c8));
	 padding: 10px 20px;
	 margin-left: -20px;
	 margin-top: 0;
	 position: relative;
	 width: 70%;

	-moz-box-shadow: 1px 1px 3px #292929;
	-webkit-box-shadow: 1px 1px 3px #292929;
       box-shadow: 1px 1px 3px #292929;

	color: #454545;
	text-shadow: 0 1px 0 white;
}

.arrow {
	 width: 0; height: 0;
	 line-height: 0;
	 border-left: 20px solid transparent;
	 border-top: 10px solid #c8c8c8;
	 top: 104%;
	 left: 0;
	 position: absolute;
}

Add Comment

Discussion 132 Comments

Comment Page 1 of 31 2 3
  1. C0de( says:

    This is awesome! thanks for the tip!

  2. Koka Koala says:

    WOW .. so qick and easy … I like it

  3. Matic says:

    Nice effect! How does it degrates in non-css3 brosers?

    • Jeffrey Way says:
      Author

      This isn’t CSS3, so it should display about the same in each browser. IE6 has trouble when using transparency as a border color. But you can just change that to the solid color of the background.

  4. Lj says:

    Wow! this is just simply amazing Jeff!

  5. Scott Corgan says:

    So much for Photoshop. Google Chrome may be my new favorite design software…

  6. Mike Taylor says:

    Hi Jeffrey,

    This is a nice lil’ technique. May I suggest adding `box-shadow: 1px 1px 3px #292929;` below the vendor specific properties, that way Opera (and maybe IE9!?!?) can play along too. :)

  7. Brian says:

    Why not just use bottom: -11px; instead of top: 104%; ? I was getting a gap in the most recent version of firefox. and, this will stay consistent even if the height of the h1 changes?

  8. Erik says:

    It even looks passable in IE. :-)

  9. Rilwis says:

    Impressive. Thanks for sharing.

  10. CodeDude says:

    Great tip there, Jeffrey. I use this so much throughout my designs…

    I seem to remember you having a similar tip a while ago…or was it my imagination?

  11. Alex P says:

    Wow! Awsome! Great job! Very creative!

  12. Giuliano says:

    Very cool! Great job as always Jeffrey.

  13. Daniel S says:

    Awesome! Bookmarked for later use. What is the name of the plugin for “CSS Live-Edit” ?

  14. KF says:

    Hi there,

    Nice job.

    Which editor are you using?

    It updates instantly. Love it!

    Cheers.

  15. Ron says:

    Thanks Jeffrey – great (and very efficient) demo.

  16. 9swords says:

    Nice how you can set the transparency and only show the shape you want.

  17. Dylan Opet says:

    Pretty useful! I’ll definitely remember this for any future projects! Thanks.

  18. Ben says:

    That was very slick, thanks for sharing!

  19. Olle says:

    This is what nettuts should be all about! Small tips & tricks and more basic stuff for us newbies!

    Good job! :)

  20. Great quick tip! :) Thanks!

  21. Aaron says:

    This is exactly what I was looking to do for my new site theme! Now I don’t have to use any images. Great work, Jeffrey!

  22. Dan says:

    Very cool tip! I had no idea that could be done in CSS…

  23. Tessa says:

    I have the worst timing, I wasted half an hour yesterday figuring this out myself, I’m sure it’l be usefull for others!

  24. Damion says:

    Great tut, thnx.

    Off topic: Can i buy only 1 month premium?

  25. edanTal says:

    Thank you for another fun CSS tutorial
    Hungry for more…

  26. Craig says:

    Wow nice one going to use this in my next project. THANKS!!!

  27. I’ve seen that before but the tut is great ! It really shows you how simple it is to make this kind of shapes.

  28. Jaspal Singh says:

    Great tutorial with CSS shapes.
    Thanks for sharing.

  29. I blinked and it was done… A lot simpler than I thought!!!

  30. Rick says:

    Thanks, will definitely be using this on some upcoming projects, I have been actively looking for image alternatives and this is perfect

  31. chetan says:

    JEFF you have to tell me , How do come to discover/invent these awesome tricks ?

  32. risetothesky says:

    It would be better for the .arrow to position it like this:
    top: 100%;
    margin-top: 2px;

    Otherwise it will have a distance when the h1 is higher than one line.
    Very Good tutorial anyway!

  33. CorvosKK says:

    Would there be a reason why you would want to avoid z-indexing the shape, rather than positioning it below? For design purposes, it seems like z-indexing would be a better choice, but I’m not sure if there’s a programming reason behind it or not. http://voxcorvin.com/tests/css/shapes_test.html

    Thanks for another awesome quick tip!

  34. quicoto says:

    Cool!

    Thanks for the tip.

    Regards

  35. Ferdinand AMOI says:

    D’une simplicité étonnante. Merci pour cet astuce.

  36. stephenfrank says:

    I’ve tried similar techniques but this is also really slick.

    Here is a technique I learned (somewhere on the internet) for transparent borders in IE6:

    .arrow {border-color: pink; filter: chroma(color=pink);

  37. dVyper says:

    I had no idea you could do this! You learn something new everyday eh…

    Excellent :-)

  38. Remmelt says:

    Jeffrey,

    I saw a similar tutorial on smashing mag a few weeks ago, is there a possibility where the fold has 3 different pictures. 1top 1 middle 1 bottom, where the view from the person who browses changes when you are a the top of the page, middle of the page, bottom of the page?

  39. Flo says:

    Awesome as always! Great tut!!!

  40. ThaClown says:

    Whow, I was doing these with images…

    This is so mutch better! THX JEFF!

  41. Derek says:

    Great job as always Jeff !! :)

  42. Bertrand says:

    Wow, that was really a neat trick!

    Instead of using “top : 104%”, couldn’t you have just used “z-index” to put the arrow behind it all?

    Thanks for the tricks!

  43. Josh says:

    I modified this slightly to go full width, looks to work in all browsers for me. Can anyone confirm?
    http://www.jgdovin.com/test.html

  44. jmarreros says:

    It’s very cool, thanks for sharing

  45. great tutorial, nice to know

  46. Felix says:

    cool! It took a while for me to understand how the fuck u dit that :P

Comment Page 1 of 31 2 3

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.