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.


Tags: CSSVideos
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Pingback: sodevious.net; design and resource blog » Blog Archive » RSS Link Love!

  • Pingback: Jose AlvarezCarbajal » Archivo » Globos de texto con CSS

  • Pingback: Cardillo y Kiwi :: » Archivo » Globos de texto con CSS

  • Chesham

    Wow, totally awesome. I’ll have to start using this.

  • Nykeri

    and we see why i luv css and this site Jeffery my friend ur a boss

  • Pingback: Eiencafe.com --> New way to graphic

  • http://adriansilimon.blogspot.com/ Adrian 7

    That’s Cool Man!

  • TheWitcher

    Nice tut Jeff, ya’ve done great job (again!).
    But one little thing I want to correct: In the Video you said, this technique is not gonna work in front of some kind of textured backgrounds; but that’s not true I think. You just need to give one border the color of the box at which the arrows is sticking to (just as you did it in the tut) and the other one ist not explicit the same color as the background but “transparent” (the span or whatever which is styled as the arrow then has to have background-color:none or transparent.
    To me that works fine with textured backgrounds.

  • http://www.saroverhees.be Saro

    Exactly what i needed!

  • http://www.antonagestam.se/ Anton Agestam

    This is just unsemantic, ugly code! How can you recommend people to use this? THIS IS NOT GOOD CODING!

    • http://www.jeff-way.com Jeffrey Way
      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!

      • http://www.antonagestam.se/ Anton Agestam

        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?

      • http://www.antonagestam.se/ Anton Agestam

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

    • Niaz Mohammed

      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

      dude, ur own website code are so terrible

  • http://www.130db.nu (zoe)

    nice

  • http://www.bmlee.com Brian

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

  • http://spotmeon.blogspot.com Gaurav M

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

  • Poonam

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

  • http://adrian-rodriguez.net Adrian Rodriguez

    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?

    • http://adrian-rodriguez.net Adrian Rodriguez

      My bad, found one little colon that looked like a semicolon, lol.

  • http://johnnemec.com John

    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

  • Pingback: CSS: Escribe tu nombre sin escribirlo! | Jugando entre diseñadores

  • Pingback: links for 2009-04-06 | Appunti di storie di web

  • http://creativeacclaim.com AlfredN

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

  • Pingback: Shapes using 100% CSS | Lively Web Tuts

  • Pingback: Revue de presse | Simple Entrepreneur

  • romain

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

  • http://www.cornerofart.com Abdullah alhourani

    Thanks

  • http://www.successcircuit.com Shane – Inspiring your Success

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

  • http://www.designeus.net Davor

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

  • omprakash

    no need for go for an image

  • http://www.mediacake.net dan

    a very useful tutorial thanks should come in handy

  • Pingback: Truques com CSS (CSS Shapes) | Createeve

  • Pingback: 100+ Massive CSS Toolbox | tripwire magazine

  • http://www.mikaelcarrara.com Mikael Carrara

    Thanks ;D

  • http://www.snackzon.se/ Erik Groda

    A very useful tutorial, thankyou very much!

  • Pingback: Weekly Updates of The Top Sites - 4 « Powerusers

  • http://pinoytayonoh.blogspot.com csseyah

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

  • Terry

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

  • Pingback: qb :: qimbox » qb : qimbox v.o17

  • Pingback: Truques com CSS (CSS Shapes) « Createeve

  • Uğur Özyılmazel

    woow… realy good

  • http://www.liquidtutorials.com jake walker

    excellant tut

  • Dean Craig

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

    Brilliant tut as usual!

  • Pingback: SAE Zen Garden « heart fist soul mind

  • Bala

    Looks Very Cool!!!

  • http://www.radoslav-angelov.co.cc Radoslav

    Strange but very cool!

  • Pingback: 50+ Promising Collection Of Resources And Inspirations For Designers To Discover The Best Of The Web In April @ SmashingApps

  • Pingback: FreeDownloadSecrets.com » Blog Archive » 50+ Promising Collection Of Resources And Inspirations For Designers To Discover The Best Of The Web In April

  • http://www.kent-website-designer.co.uk/ Website Design Kent

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

  • Pingback: CSS Tip: How to Make Circles Without Images | Dev Tips | Become a Better Developer, One Tip at a Time.

  • EDimNETZ

    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?

  • EDimNETZ

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

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

  • Pingback: 50 Incredible Tutorials from the Tuts+ Network | Free Tutorial 4 All

  • Pingback: 50 Incredible Tutorials from the Tuts+ Network - News ums Netz