deviant art

Deviant Login Shop  Join deviantART for FREE Take the Tour
×

×

CSS Snippets: Wrapped Header

Journal Entry: Sat Oct 15, 2011, 1:44 PM
:iconikue:
CSS { Snippets : Wrapped Header }

Welcome to the first installment of my CSS Snippets journals. I've had a lot of questions over the years about how I create/achieve some of the elements in my journal skins so I thought I'd try my hand at a tutorial of sorts for the different elements I find fascinating and some of the work arounds needed to make them function properly when limited by deviantART's  journaling system. Although, "limited" doesn't feel like the correct word. To me it's more of a challenge and to persevere through it really gives me a thrill I just can't explain. It's not really a limitation as it forces one to think outside the box and hopefully when you get it just right, you'll get that same thrill.

I had originally planned to start these journal tuts after the new Journal/News system and Sta.sh Writer had been launched. I think showing you live what happens when CSS meets HTML would negate the need for a separate downloadable file, like is common in most other CSS tutorials found in the resources gallery. That along with the new Journal/News systems faving feature, you could add one of these Snippet journals to your favs and reread them at your own leisure. And with the Sta.sh Writer feature I could reBlog these journals across the CSS groups I'm a part of and reach a larger community. Plus... How sexy is this journal skin? Very, if I do say so myself! ;) Anyway, I've decided not to wait that long since I'm pretty impatient and I've had this journal skin coded up for a while just waiting to pounce. For those of you that are Beta testers you can feel free to add these journals to your favs the rest of you will just have to visit my journal tab on my userpage until the new system launches site wide.


:iconikue:
Wrapped Header

So now to the reason we're all here. I'd like to show you how to make a wrapped effect using just HTML and CSS. In list tutorial you'll learn how to hijack the <h1> header tag and turn it in to a way to break up you journal entries. You'll also learn how to to create a triangle shape using the border property in your CSS.

First off, let's start with the HTML we'll need. The elements below will be used to to create the container that holds the text, the header that is the title of the new topic and finally the triangle.

So since deviantART's journaling system only allows you to use descendant and class selectors we'll need to make 3 new class selectors. One for the container, one for the header and one for the triangle.


html
  1. <div class="container">
  2. <H1>Title
  3. <div class="triangle"></div>
  4. </H1>
  5. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor. Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus.
  6. </div>

:iconikue:
Styling the elements

In the code above I have used 2 class selectors and a H1 tag. If you're planning on using this code in your own journals you can skip the first container class since your journal comes prebuilt with a .Journalbox or .text CSS property and you can just target one of those in your CSS to adjust its properties. We could have also used a Class selector instead of a <h1> tag but I like that it keeps the markup fairly clean and you might as well reuse elements that are already built in.

With the HTML out of the way, let's get to altering the CSS and skinning these elements.


css
  1. .container {
  2. background: #A8A8A8;
  3. color: #FFF;
  4. padding: 20px 20px 20px 20px;
  5. width: 200px;
  6. font-size: 12px;
  7. margin: auto;
  8. position: relative;
  9. }
  10. .container h1 {
  11. background: #828282;
  12. color: #FFF;
  13. padding: 5px 25px 5px 30px;
  14. font-size: 18px;
  15. margin-left: -30px;
  16. position: relative;
  17. }
  18. .container .triangle {
  19. width: 0;
  20. height: 0;
  21. bottom: -10px;
  22. left: 0;
  23. border-left: 10px solid transparent;
  24. border-top: 10px solid #4C4C4C;
  25. position: absolute;
Hover for more

:iconikue:
The results

In the CSS for the container selector I've set a width of 200 pixels. This won't be necessary for your actual journal since that will stretch with the page. If you do set a width for this area, setting the margin as "auto" will allow the box to remain centered on the page when it's stretched wider than the box.

For the h1 tag we need to set a negative margin so that the header breaks out of the container box and is off to the left side.  The exact pixel distance is of course your preference but keep in mind that the number may be higher than you think because of the padding on the header. Take notice that we have the position set to relative. This is very important for the next step when aligning the triangle.

Finally, the triangle. We need no width or height for this element because this will be made by the border pixel size. As you can see in the CSS the borders are set to 10 pixels and given a colour. In the case of the left border this colour is transparent. When combined with another border that has a colour, in this case the top border, it creates a triangle. Were you to use a transparent right border this triangle would be flipped the opposite direction. Likewise, if you were to use a transparent top border and an opaque left or right border the triangle would be flipped upside down. Because the size of these border is 10 pixels it stands to reason that the height of this element is now 10 pixels. With this in mind we will need to move this element down 10 pixels using the negative bottom CSS property. To finish it off we ensure the position of this object is set as absolute. Keep in mind, if you were to use the position property as absolute without first setting the parent element (in this case h1) as relative this element would have been at the very bottom of the journal, far away from where you wanted it to be.

If you've got all that done correctly here's what you should have:



Title

  
Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor. Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus.


html
  1. <div class="container">
  2. <H1>Title
  3. <div class="triangle"></div>
  4. </H1>
  5. Vivamus hendrerit arcu sed erat molestie vehicula. Sed auctor neque eu tellus rhoncus ut eleifend nibh porttitor. Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus.
  6. </div>

css
  1. .container {
  2. background: #A8A8A8;
  3. color: #FFF;
  4. padding: 20px 20px 20px 20px;
  5. width: 200px;
  6. font-size: 12px;
  7. margin: auto;
  8. position: relative;
  9. }
  10. .container h1 {
  11. background: #828282;
  12. color: #FFF;
  13. padding: 5px 25px 5px 30px;
  14. font-size: 18px;
  15. margin-left: -30px;
  16. position: relative;
  17. }
  18. .container .triangle {
  19. width: 0;
  20. height: 0;
  21. bottom: -10px;
  22. left: 0;
  23. border-left: 10px solid transparent;
  24. border-top: 10px solid #4C4C4C;
  25. position: absolute;
Hover for more

:iconikue:
Conclusion

So, with all that neatly tucked away in your journal, please, feel free to alter and tinker with this CSS to customize it to your tastes.  Here's an example of what I was able to make using elements from this journal, all without using a single image file:



The time has come, my little friends, to talk of other things / Of shoes and ships and sealing wax, of cabbages and kings / And why the sea is boiling hot, and whether pigs have wigs / Calloo, Callay, come run away / With the cabbages and kings.
  
        

The Walrus - 1951

  
  
     


:iconikue:
Finalé

My apologies for the length of this journal. With the intro taking us so much space it was longer than I anticipated. Hopefully the next installment shouldn't be as large.

Speaking of the next installment. I have several other elements lined up but please, feel free to suggest topics you would like me to cover. I'm also more than happy to answer any questions within my means should you ask in a comment below. :)

Please feel free to leave any comments or critisism on the layout/flow of this journal. Is it too hard to follow? What could I improve? Any extra feedback would be appreciated.



!
Warning: These tutorials are only tested in Safari and Firefox.
Much like the boogieman that lives under your bed, I do not believe in Internet Explorer. If you're looking for assistance with coding for this browser you have come to the wrong place.

2,026

47 58 0

Details

Stats

Submitted on
October 15, 2011
Views
2,026
Favourites
47 (who?)
Comments
58
URL
Thumb
Only verified accounts can report policy violations. Please check your email and click on the verification link.
* Required field
Add a Comment:
 
:icongillianivy:
`GillianIvy Mar 10, 2013  Hobbyist General Artist
And this! [link]
Reply
:iconinfinite-heart:
`Infinite-Heart Dec 12, 2012   General Artist
:la:
Reply
:iconikue:
$Ikue Dec 13, 2012  Hobbyist Digital Artist
e.O Where did you find this?

:giggle:
Reply
:iconinfinite-heart:
`Infinite-Heart Dec 13, 2012   General Artist
Google. I am trying to learn to code, kind of.
Reply
:iconikue:
$Ikue Dec 13, 2012  Hobbyist Digital Artist
Best of luck! :D
Reply
:iconinfinite-heart:
`Infinite-Heart Dec 13, 2012   General Artist
:tighthug:
Reply
:iconcyphervisor:
Featured here Feature-O-Matic - Edition #02

Consider faving:+fav: it! :hug:
Reply
:iconpica-ae:
^pica-ae Feb 27, 2012  Professional Interface Designer
Dammit, this was one of the things that got deleted when I cleaned my message center in November :noes:

This would have saved me fiddlind with images to create triangle corners :la:
Reply
:iconikue:
$Ikue Mar 2, 2012  Hobbyist Digital Artist
:huggle:
Reply
:iconsatania:
^SaTaNiA Feb 13, 2012  Hobbyist Digital Artist
:worship:
Reply
Add a Comment: