Fun With CSS Shapes
videos

Fun With CSS Shapes

I bet a bunch of you don’t realize that we can create the illusion of shapes by using 100% CSS. By utilizing the border property in creative ways, we can make some really interesting polygons. In this week’s screencast, we’ll figure out a way to create speech-bubbles without resorting to background images.

Most of us, by now, are familiar with using the “-moz-border-radius” and “-webkit-border-radius” properties to create rounded corners – or even complete circles – but there are other techniques to create more complicated shapes.

Traditional Speech-Bubble

css shapes
blockquote#one {
 width: 250px;
background: #e3e3e3;
padding: 25px;
position: relative;
}

#one .arrow {
 width: 0;
 height: 0;
 line-height: 0;
 border-top: 30px solid #e3e3e3;
 border-left: 60px solid white;
 border-right: 10px solid white;
 position: absolute;
 bottom: -30px;
 right: 30px;
}

Note how the “bottom” property is the reciprocal of the “border-top” property.

Alternate

css shapes
blockquote#two {
 width: 250px;
background: #e3e3e3;
padding: 25px;
position: relative;
}

blockquote#two .arrow {
 width: 0;
height: 0;
line-height: 0;
border-top: 40px solid #e3e3e3;
border-left: none;
border-right: 30px solid white;
position: absolute;
bottom: 60%;
right: -30px;
}

Yet Another

css shapes
blockquote#three {
 width: 450px;
 background: #e3e3e3;
 padding: 25px;
 position: relative;
}

#three .arrow {
 width: 0;
 height: 0;
 line-height: 0;
 border-bottom: 25px solid #e3e3e3;
 border-right: 50px solid white;
 position: absolute;
 top: -24px;
 left: 20px;
}
css shapes

Interesting Note

I’m typing this paragraph minutes before posting the tutorial. I learned something tonight. Did you know that, if you want your document to validate, you can’t place text directly into a blockquote? It needs to be nested within a parent element – like the <p> tag. Additionally, the validator didn’t like the fact that I used a span tag within the blockquote. It allows for a plethora of elements, but unfortunately not the span! Oh well; no big deal. Just replace it with a different element. It hardly makes a difference.

Span tag within a blockquote

Pretty Nifty

I’m really eager to see how you guys have implemented this unique trick into your own projects. Send us links to your examples, via the comments. Thanks for watching. Next week, plan on learning something much more advanced. …I just need to figure out what! Until then.


Add Comment

Discussion 119 Comments

Comment Page 3 of 3 1 2 3
  1. This is just unsemantic, ugly code! How can you recommend people to use this? THIS IS NOT GOOD CODING!

    • Jeffrey Way says:
      Author

      Care to elaborate? Also, be sure to let me know how using a class of “textcenter” on your own website is a smart idea.

      Thanks!

      • What I mean is that it to me seams very “unsemantic” to use an element just to the purpose of styling. Wouldn’t that look pretty nasty, or at least not “as it should look like” if you turn off css style sheets in the web developer tool bar? I’ve always been tought to code semantic and to use the elements to what they are meant to be used to.

        The reason I use a textcenter class on page is simply that I often have more than one element in my pages that have centred text. If I can define one less ID, I will keep my css file smaller, will I not?

      • You explain to me how not using and index file on your website is a smart idea! ;)

    • Niaz Mohammed says:

      excuse me?

      rel=”stylesheet” href=”style.php” @ your own site?

      Is that some kind of elite way to throw us designers off track? Or is it just symantic, beautiful code, in your humble opinion?

    • Dave says:

      dude, ur own website code are so terrible

  2. Brian says:

    Great post.
    This looks very simple and easy.
    Thanks.

  3. Gaurav M says:

    this is awesome man great!! stuff
    the Homer was also nice …
    http://www.romancortes.com/blog/homer-css/

  4. Poonam says:

    Hey very nice………Got new thing to learn :) cheers !

  5. Every time I am working on #three .arrow the arrow is not showing up. When I look at it in firefox firebug isn’t showing me border-bottom: 25px solid #e3e3e3;
    and only shows the border-right style. The weird thing is that I have the style set in my css, but it’s not showing up. Know why this is happening?

  6. John says:

    very good stuff, i’ve been looking for a useful way of using this technique for a while… the best I could come up with was my CSS Heart

  7. AlfredN says:

    I have a hard time with these myself, this tutorial will prove useful in the future.

  8. romain says:

    <= Why don’t use it for your own comments ??? :p

  9. So thats how you do it!!! Been looking for something like that for a very long time.

  10. Davor says:

    Excellent tutorial! It’s going to be very useful for my current project. Thank you ;)

  11. omprakash says:

    no need for go for an image

  12. dan says:

    a very useful tutorial thanks should come in handy

  13. Erik Groda says:

    A very useful tutorial, thankyou very much!

  14. csseyah says:

    very nice bro.. i learn a lot to your tutorial. God Bless You bro

  15. Terry says:

    You can position the shape in the corner of the container element and make it look like the box is folded on the corner.

  16. Uğur Özyılmazel says:

    woow… realy good

  17. Dean Craig says:

    Very interested in the last part, about the tags on the validator, never knew that.

    Brilliant tut as usual!

  18. Bala says:

    Looks Very Cool!!!

  19. Radoslav says:

    Strange but very cool!

  20. Some excellent CSS resouce info here. Keep up the good work.

  21. EDimNETZ says:

    Thanks for this great tutorial!
    Very helpful to a noob like me.

    Two questions though:
    So which tag to take instead of to make the CSS validate?
    And how do make it work in IE6?

  22. EDimNETZ says:

    Hm … apparantly I can’t write this “<” here.

    I meant:
    Which tag to use instead of “span” to make it validate?

  23. Crazyguy Reegan says:

    Simply amazing.

  24. Ali Naqvi says:

    hello there !! i just dicovered this site and i found it very helpful, will be coming back to it in the future

  25. mojitopl says:

    Jeff – You just make thigs eeeeeeasy. I saw sam tutorial for this arrow stuff, but people get too comlicated. You’re The Shit! ;) thanks

  26. adrusi says:

    why use a color for the invisible borders? _px solid transparent works well, so does none, and 0;

  27. I was hoping to see some more examples. May be if you could create some more and show us mortals some tricks ;)

  28. Chris says:

    Awesome Tut.

  29. lorth says:

    First example dont work in FF 3.6 without JS.
    Way to go to call it “100% CSS”.

  30. Excellent, thanks for this, i’ll be using this on my vbulletin 4 styles website, i will leave full credits to your site so my visitors can learn this also, Thanks

  31. Rob Allison says:

    Very interesting!! I was experimenting with this kinda thing and managed to reproduce the mushroom from Mario Brothers.
    http://www.rob-allison.co.uk/fun-with-css-rounded-corners/

  32. Shiela says:

    hi i’m shiela thanks for the tutorial i wish you will make a video and post it into youtube

  33. jmarreros says:

    I always use an image, I never thought it, thanks

  34. ibbrxx says:

    Whoever says whatever, Jeffrey Way you rock in every way.

  35. Olá! Bom dia!

    Estou acompanhando teus tutoriais aqui do Brasil e estou gostando muito! Estão servindo muito para o meu aprendizado.

    Obrigado.

    Hi, Morning there!

    I am following your tutorials from Brazil and like so much! They are serving for my learning, a lot!

    Thanks anyway.

  36. lawfun says:

    thank you? Very useful!

  37. Very detailed article would it be OK if i translate into French for my sites subscribers? Thanks

  38. mohammad says:

    the Homer was also nice …

  39. Thanks for the great post

    I’ve got to admit … I didn’t know that this was possible before seeing this tut …

    Awesome share

    =)

  40. Will says:

    If #e3e3e3 looks “blue” to you, you need to check your monitor/display settings. #e3e3e3 is grey.

  41. Shekhar says:

    I used this to clear breadcrumb nav. I need to change this shape’s color on hover, but can’t do.

    See my CSS

    .orgSubMenu li a span{border-style:solid; border-color:transparent transparent transparent #818181; border-width:4px 5px; width:0; height:0; float:left; margin:4px 0 0;}

    .searchPage .orgSubMenu li a:hover span, .searchPage .orgSubMenu li a:focus span {
    border-color: transparent transparent transparent #4A751C !important;
    }

  42. Shekhar says:

    Sorry, I was to say ‘create’ instead of ‘clear’ on the comment above.

    Checkout demo of my problem here: http://jsfiddle.net/ty3GF/4/embedded/result/

    Plz reply soon Jeffrey.

  43. kentwebhost says:

    Great stuff, thanks

Comment Page 2 of 2 1 2

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.